working solution gets you $5 paypal

Discussion in 'Programming' started by cavendano, Oct 13, 2007.

  1. #1
    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):
     
    cavendano, Oct 13, 2007 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    As Seller:
    100% - 0
    As Buyer:
    0.0% - 0
    #2
    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.
     
    papa_face, Oct 13, 2007 IP
  3. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    are you done? or do u still want it?
     
    undir, Oct 13, 2007 IP