I have an auto delete script that checks my site everytime its ran to ensure files are not older than x. right now it works great but on one of the directories I added a html file so that users wouldnt be able to see the files in a download folder. the problem is that this line currently clears out all files except the .htaccess. it clears out even the index.html even though .html is an array. delete_old_files('temp' , 172800 , array('.htaccess','.html')); PHP: any help would be appreciated.
Here is the entire script: <?php function delete_old_files($directory,$seconds_old,$exclude) { if( !$dirhandle = @opendir($directory) ) return; while( false !== ($filensame = readdir($dirhandle)) ) { if( $filensame != "." && $filensame != ".." ) { if (!in_array($filensame , $exclude)) { $filensame = $directory. "/". $filensame; if( @filemtime($filensame) < (time()-$seconds_old) ) @unlink($filensame); } } } } delete_old_files('gcd' , 172800 , array('.htaccess')); delete_old_files('uploadedFiles' , 3600 , array('.htaccess')); delete_old_files('temp' , 172800 , array('.htaccess','.html')); ?> PHP:
hi, it is deleting the file because it compares ,html to the full name of the file(not just .html) try putting the whole file name of the .html file in the array instead