Deleting files with PHP

Caporegime
Joined
18 Oct 2002
Posts
25,287
Location
Lake District
I have a webcam set up which takes an image every minute, over the course of a day this is a lot of files!

I want to write a maintenance routine so when the page is loaded is deletes all the files older than say a day. Does anyone know how I might go about this?
 
These might help. http://www.tizag.com/phpT/filedelete.php http://www.webmasterworld.com/forum88/3217.htm

But it depends on how your images are created and organised. Hopefully they are in daily folders (using a proper time stamp would let you handle the deletion of X day old folders a lot nicer) and the images are named 1.jpg, 2.jpg? Or if the file name itself has a time stamp in it, you could use that as the selection method to loop through and unlink.

If not, I would consider making some changes to your image creation to make the maintenance process a bit easier. As all you need then is loop through the files, unlink them and then rmdir the folder to remove that.
 
Back
Top Bottom