1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- if (php_sapi_name() != 'cli') {
- exit;
- }
- $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) {
- recursive_delete($a_dir.'/'.$item);
- }
- }
- function recursive_delete($str){
- if (is_file($str)) {
- return @unlink($str);
- } elseif (is_dir($str)) {
- $scan = glob(rtrim($str,'/').'/*');
- foreach ($scan as $index=>$path) {
- recursive_delete($path);
- }
- return @rmdir($str);
- }
- }
|