cavendano Posted October 10, 2007 Share Posted October 10, 2007 This script was meant to delete a file after X days...in this case I wanted it to delete files that were older than 1 day except .htaccess. what the script is doing is deleting everything in the specified folders except htaccess even though the files are less than a day old. any suggestions? <?php function delete_old_files($dir, $time_limit = 0,$exclude=array()){ if(!$time_limit) $time_limit = 1*24*60*60; if ($df = opendir($dir)) { while (false !== ($file = readdir($df))) { if ($file != "." && $file != "..") { $last_modified = filemtime($file); if((time()-$last_modified > $time_limit) && !in_array($file , $exclude)){ unlink($dir."/".$file); } } } closedir($df); } }delete_old_files('gcd' , 10 , array('.htaccess')); delete_old_files('uploadedFiles' ); delete_old_files('temp' ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/72634-auto-delete/ Share on other sites More sharing options...
freakstyle Posted October 10, 2007 Share Posted October 10, 2007 its not clear what folder you are seeing the function delete anything, but looking at your code you call the function 3 times, the last two of which will use your default time_limit of 0 days. looking at your function i think you mean to have the time limit be null not 0, 0 could be assumed a numeric value vs false if you provide more details into what folder is having the issue we might have more insight for ya good luck Quote Link to comment https://forums.phpfreaks.com/topic/72634-auto-delete/#findComment-366232 Share on other sites More sharing options...
cavendano Posted October 10, 2007 Author Share Posted October 10, 2007 all folders are getting their files deleted....if i upload a file into all three directories and run the script it deletes it.... the gcd, temp, and uploadedFiles folders lose all their files regardless of creation time Quote Link to comment https://forums.phpfreaks.com/topic/72634-auto-delete/#findComment-366249 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.