View Single Post
Old 10-22-2009, 02:05 AM  
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,479
Quote:
Originally Posted by AIbenjamink View Post
Here you go. Hasn't been tested:

PHP Code:
$dir '/www/';
$Files=array();

if (
$handle opendir($dir)) {

  while (
false !== ($file readdir($handle))) {
    if (
$file[0] == '.' || is_dir("$dir/$file")) {
      continue;
    }
    if ((
time() - filemtime($file)) > ($days *86400)) { //7 days
      //unlink("$dir/$file");
      
$Files[$dir/$file]=filemtime($file);
    }
  }
  
closedir($handle);

  
//Sort the array by file modified times, reverse sort
  
arsort($Files);

  
//Remove the newest 3 files from the array
  
$Files=array_slice($Files3);

  
//Remove the remainder of files
  
foreach($Files as $FilePath=>$ModifiedTime)
  {
      
unlink($FilePath);
  }

Thanks, will look into it. However, you say this:
//Remove the newest 3 files from the array

Obviously we want to kill the oldest, not the newest, right?

So how does that come about?
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote