brentmoeller Posted February 26, 2011 Share Posted February 26, 2011 when the blow code is ran it produces this warning error Warning: filemtime() [function.filemtime]: stat failed for 048_Baby_Colors.png in /home/public_html/.com/kill.php on line 23 The code deletes all the files in the directory no matter how many hours or seconds ago they was last modified. could someone help me figure out why? <?php $dir = '/home/br/public_html/l.com/dfile'; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file[0] == '.' || is_dir("$dir/$file")) { continue; } if ((time() - filemtime($file)) > ($days * 604800)) { unlink("$dir/$file"); } } closedir($handle); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228905-deletes-all-files/ Share on other sites More sharing options...
litebearer Posted February 26, 2011 Share Posted February 26, 2011 this may help - http://stackoverflow.com/questions/3126191/php-script-to-delete-files-older-than-24-hrs-deletes-all-files Quote Link to comment https://forums.phpfreaks.com/topic/228905-deletes-all-files/#findComment-1179951 Share on other sites More sharing options...
brentmoeller Posted February 26, 2011 Author Share Posted February 26, 2011 this may help - http://stackoverflow.com/questions/3126191/php-script-to-delete-files-older-than-24-hrs-deletes-all-files Thanks for the find, but i dont see a solution that helps resolve the above issue i attempt all the suggested fixes Quote Link to comment https://forums.phpfreaks.com/topic/228905-deletes-all-files/#findComment-1179952 Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2011 Share Posted February 26, 2011 What do you get if you echo the filemtime() value? Does it appear to be a valid timestamp? Quote Link to comment https://forums.phpfreaks.com/topic/228905-deletes-all-files/#findComment-1179997 Share on other sites More sharing options...
PFMaBiSmAd Posted February 26, 2011 Share Posted February 26, 2011 0 * 604800 is zero and just about every (time() - filemtime($file) is going to be greater than zero. Quote Link to comment https://forums.phpfreaks.com/topic/228905-deletes-all-files/#findComment-1180038 Share on other sites More sharing options...
DavidAM Posted February 26, 2011 Share Posted February 26, 2011 Warning: filemtime() [function.filemtime]: stat failed for 048_Baby_Colors.png in /home/public_html/.com/kill.php on line 23 This seems to indicate that the system could not find the file that you passed to filemtime(). Since it also shows the filename it was looking for, you can see that there is no directory path specified in the value passed to filemtime(). I think you need to add the directory you are searching to that call: filemtime($dir . '/' . $file) Quote Link to comment https://forums.phpfreaks.com/topic/228905-deletes-all-files/#findComment-1180050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.