I'm really trying to delete files older than 1hr old. I've found this script through another post and having some trouble with it.
$dir = '/home/directory_location/files';
if ($handle = opendir($dir)) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
if ($file[0] == '.' || is_dir("$dir/$file")) {
// ignore hidden files and directories
continue;
}
if ((time() - filemtime($file)) > ($days *86400)) {
unlink("$dir/$file");
}
}
closedir($handle);
}
1. i have files a few days old and less than 1hr old and the script deleted 100% of the files
2. for each file on the resulting php page, the following error returned:
Warning: filemtime() [function.filemtime]: stat failed for devadminb1a8b72a0d0c1c9f26ef74123b254addgolfrounds.zip in /home/directory_location/maintain.php on line 13
I am assuming it is referring to this line but I am unsure of how to resolve.
if ((time() - filemtime($file)) > ($days *86400)) {