ha.M.ed
ha.M.ed

Reputation: 985

Delete files after deleting a specific row of a table

I have a table that store the ADDRESS of uploaded files. e. g. "upload/news/pic1.jpg" .

Now my question is:

How can I delete these uploaded files after deleting rows from table. Is there a way to do this automatically? I can't let them stay on host permanently!

thanks...

Upvotes: 0

Views: 35

Answers (1)

Sverri M. Olsen
Sverri M. Olsen

Reputation: 13283

Go through the file names and delete the files.

foreach ($files as $filepath) {
    unlink('/path/to/root/'.$filepath);
}

Then delete the file names from the database.

Computers are stupid. They will only do something if you tell them to do it.

Upvotes: 1

Related Questions