You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
843 B
32 lines
843 B
15 years ago
|
<?php
|
||
|
if (php_sapi_name() != 'cli') { exit; } //do not run from browser
|
||
|
$dir = dirname(__FILE__);
|
||
|
$a_dir = realpath($dir.'/../../archive/');
|
||
|
$list = scandir($a_dir);
|
||
|
$t = time()-(86400*7);
|
||
|
foreach($list as $item) {
|
||
|
if (substr($item,0,1) == '.') { continue; }
|
||
|
$stat = @stat($a_dir.'/'.$item);
|
||
|
if ($stat === false) { error_log('Cron task cannot stat '.$a_dir.'/'.$item); continue; }
|
||
|
if ($stat['mtime'] > $t) { //if the file is older than one week, delete
|
||
|
recursiveDelete($a_dir.'/'.$item);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Delete a file or recursively delete a directory
|
||
|
*
|
||
|
* @param string $str Path to file or directory
|
||
|
*/
|
||
|
function recursiveDelete($str){
|
||
|
if(is_file($str)){
|
||
|
return @unlink($str);
|
||
|
}
|
||
|
elseif(is_dir($str)){
|
||
|
$scan = glob(rtrim($str,'/').'/*');
|
||
|
foreach($scan as $index=>$path){
|
||
|
recursiveDelete($path);
|
||
|
}
|
||
|
return @rmdir($str);
|
||
|
}
|
||
|
}
|