almost there...

Discussion in 'PHP' started by cavendano, Nov 16, 2007.

  1. #1
    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.
     
    cavendano, Nov 16, 2007 IP
  2. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #2
    hi,

    it's quite hard to tell since you did not show the content of the function delete_old_files()
     
    serialCoder, Nov 16, 2007 IP
  3. cavendano

    cavendano Well-Known Member

    Messages:
    360
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #3
    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:
     
    cavendano, Nov 16, 2007 IP
  4. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #4
    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
     
    serialCoder, Nov 16, 2007 IP
    cavendano likes this.