this is an auto delete script it is supposed to look at a files age and delete files older than 7 days old.. right now the script deletes everything regardless of age except htaccess... if you can fix this to do delete only files older than 7 days old and leave the rest alone you will get $5 paypal for your working response... thanks! <?php function delete_old_files($dir, $time_limit = 604800,$exclude=array()){ if(!$time_limit) $time_limit = 7*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' , 604800 , array('.htaccess')); delete_old_files('uploadedFiles' ); delete_old_files('temp' ); ?> Code (markup):
Try: function delete_old_files($directory,$seconds_old,$exclude) { if( !$dirhandle = @opendir($directory) ) return; while( false !== ($filename = readdir($dirhandle)) ) { if( $filename != "." && $filename != ".." ) { if (!in_array($filename , $exclude)) { $filename = $directory. "/". $filename; if( @filemtime($filename) < (time()-$seconds_old) ) @unlink($filename); } } } } delete_old_files('gcd' , 604800 , array('.htaccess')); Code (markup): Untested, but should work. Edit: Just tested and it works. PM me if you need anything added.