2
I wonder if anyone knows any way to create a "trigger" in Mysql that when deleting a table value, delete a file together on the server, for example:
- Excludes the item from
tbl_imagens
whose name isimagem_1001.jpg
; - The trigger takes the value
imagem_1001.jpg
and deletes in the directoryuploads/imagem_1001.jpg
Obs:
- I don’t care to save images in the database;
- I don’t care to delete with PHP
unlink()
;
Do you really need to delete a file through Mysql? You cannot use the programming language?
– Renaro Santos
I don’t see much logic in doing this for the bank, and I don’t know if there’s a possibility. As you are working with a programming language make this exclusion with it, will be more coherent.
– Otto
Yes, and searching, I saw people commenting that can insert linux commands in the trigger. RM for example;
– adrianoAcosta
Yes, there is a lot of logic in this, you will be avoiding many conditions and queries in a given system that makes use of a complex image chain
– adrianoAcosta
An alternative would be to create a table of
imagens_para_excluir
. This table could be run from a sheel script that queries this table, removes the files from the disk and truncates that table. You could schedule the execution of this script via cronjob.– gmsantos
I agree with the comment of @gmsantos. Separation of concepts: Database is for storing data, Filesystem for managing files. Some other layer of the solution should do the file purge.
– OnoSendai
Managed to solve your problem?
– durtto