We given php code for Checking directory and deleting one day old files from folder using php, from folder in windows or linux through php language. For deleting the files from folder in any system (windows or linux). I created the PHP script for deleting the old files from system.
Earlier I created the script for deleting files from folder but that was for only linux. Then I created script which will work independently. Following script will work in mac or windows or linux.
deleting one day old files from folder using php
/***************** Delete one day old files ****************/ $dir = "C://Inetpub/vhosts/yourdomain/tmpfiles"; if (is_dir($dir)) { if ($dh = opendir($dir)) { while ($file = readdir($dh)) { if(!is_dir($dir.$file)) { if (filemtime($dir.DIRECTORY_SEPARATOR.$file) < strtotime('-1 days')) { //if 1 days old, delete <div id=":1o">echo "Deleting $dir.$file (old)\n"; unlink($dir.$file); } } } } else { echo "ERROR. Could not open directory: $dir\n"; } } else { echo "ERROR. Specified path is not a directory: $dir\n"; } closedir($dh); // Above script is platform independent.</div>
Shouldn’t your less than be a greater than in the line:
if (filemtime($dir.DIRECTORY_SEPARATOR.$file) < strtotime('-1 days')) { //if 1 days old, delete
Just wondering. Great code btw.