Jump to content

delete files in folder, file name value less than todays date and time - 1 hr


jasonc

Recommended Posts

I am wanting to delete temporary files from a folder that have a file name value of todays date minus one hour and all files created before this time.

 

i have the following but this only works for files created on the day this script is run, if i get no members for a day or two then files created will remain in folder and each time this happens more and more are kept.

 

what is the best way to code the below to get this to work

 

<?
foreach (glob("temp_files/" . gmdate("Y-m-d_") . "*.png") as $filename) {
unlink($filename) or die($errorcode = mysql_error());
if (isset($errorcode)) {
echo("error in delete");
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.