Possible Duplicate:
How to delete files from directory based on creation date in php?
How would i delete all the images in a folder that are 24 hours old or older in php?
Possible Duplicate:
How to delete files from directory based on creation date in php?
How would i delete all the images in a folder that are 24 hours old or older in php?
$imagePattern = "/\.(jpg|jpeg|png|gif|bmp|tiff)$/";
$directory = ".";
if (($handle = opendir($directory)) != false) {
while (($file = readdir($handle)) != false) {
$filename = "$directory/$file";
if (strtotime("-24 hours") <= filemtime($filename) && preg_match($imagePattern, $filename)) {
unlink($filename);
}
}
closedir($handle);
}
combination of:
to check time http://us2.php.net/manual/en/function.filemtime.php
An alternate solution would be to use a naming convention that includes a unix timestamp if you have control over that.
shell_exec('find /path/to/files* -mtime +1 -exec rm {} \;');