Need php cron jobs to auto dlete files after XX hours [$5]

Discussion in 'Programming' started by Hipto, Sep 15, 2010.

  1. #1
    Hey guys, I needthis PHP cron job script which can automatically delete files within a partiuclar folder, after like 12 hours, corresponding to the 'Last Modified' Date of the file.

    Note: I'm NOT looking for cron to remove files every 12 hours..
    $5 to someone who can code it
     
    Last edited: Sep 15, 2010
    Hipto, Sep 15, 2010 IP
  2. smurfas666

    smurfas666 Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    Here is the script:

    
    //$_SERVER['DOCUMENT_ROOT']='';
    
    $path=$_SERVER['DOCUMENT_ROOT'].'/your_folder';
    
    $now_minus_12h=time()-43200;
    $folder=dir($path);
    while ($entry = $folder->read())
    {
    	$file=$path.'/'.$entry;
    	if (!is_dir($file))
    	{
    		$modified=filemtime($file);
    		if ($modified<$now_minus_12h) unlink($file);
    	}
    }
    $folder->close();
    
    Code (markup):
    Just set the cron to run every 5 or 10 minutes. Also you may have to manually set $_SERVER['DOCUMENT_ROOT'].

    Vilius
    smurfas666@hotmail.com
     
    smurfas666, Sep 16, 2010 IP