예제 #1
0
    } else {
        echo "Aborting deletion.\n\n";
        die;
    }
}
$count = 0;
foreach ($folderToProcess as $folder) {
    $folder = $basePath . $folder;
    if (file_exists($folder)) {
        foreach (new DirectoryIterator($folder) as $fileInfo) {
            if ($fileInfo->isDot() || $fileInfo->isDir()) {
                continue;
            }
            if (time() - $fileInfo->getCTime() > $days * 24 * 60 * 60) {
                $currentFilename = $fileInfo->getFilename();
                if (skipFile($currentFilename)) {
                    //      echo "skipping file $currentFilename" . "\n";
                } else {
                    echo "deleting: " . $fileInfo->getRealPath() . "\n";
                    unlink($fileInfo->getRealPath());
                    $count++;
                }
            }
        }
    }
}
// end foreach
echo "Run complete. {$count} files deleted.\n";
function skipFile($filename)
{
    global $filesToKeep;
예제 #2
0
파일: rules.php 프로젝트: undomick/cgru
function walkDir($i_recv, $i_dir, &$o_out, $i_depth)
{
    global $FileMaxLength;
    if ($i_depth > $i_recv['depth']) {
        return;
    }
    if (false == is_dir($i_dir)) {
        $o_out['error'] = 'No such folder.';
        return;
    }
    $rufolder = null;
    if (array_key_exists('rufolder', $i_recv)) {
        $rufolder = $i_recv['rufolder'];
    }
    $rufiles = null;
    if (array_key_exists('rufiles', $i_recv)) {
        $rufiles = $i_recv['rufiles'];
    }
    $lookahead = null;
    if (array_key_exists('lookahead', $i_recv)) {
        $lookahead = $i_recv['lookahead'];
    }
    $access = false;
    $denied = true;
    if (htaccessPath($i_dir)) {
        $access = true;
        $denied = false;
    } else {
        $rufiles = array('rules');
        $o_out['denied'] = true;
    }
    if ($handle = opendir($i_dir)) {
        $o_out['folders'] = array();
        $o_out['files'] = array();
        $walk = null;
        $walk_file = $i_dir . '/' . $rufolder . '/walk.json';
        if (is_file($walk_file)) {
            if ($wHandle = fopen($walk_file, 'r')) {
                //error_log($path);
                $wdata = fread($wHandle, $FileMaxLength);
                //error_log($wdata);
                $walk = json_decode($wdata, true);
                fclose($wHandle);
            }
        }
        while (false !== ($entry = readdir($handle))) {
            if (skipFile($entry)) {
                continue;
            }
            $path = $i_dir . '/' . $entry;
            if ($access && false == is_dir($path)) {
                if (is_file($path)) {
                    $fileObj = array();
                    if (false == is_null($walk) && isset($walk['files']) && isset($walk['files'][$entry])) {
                        $fileObj = $walk['files'][$entry];
                    }
                    $fileObj['name'] = $entry;
                    $fileObj['size'] = filesize($path);
                    $fileObj['mtime'] = filemtime($path);
                    array_push($o_out['files'], $fileObj);
                }
                continue;
            }
            if ($entry == $rufolder && is_dir($path)) {
                $o_out['rufiles'] = array();
                $o_out['rules'] = array();
                if ($rHandle = opendir($path)) {
                    while (false !== ($ruentry = readdir($rHandle))) {
                        if ($ruentry == '.') {
                            continue;
                        }
                        if ($ruentry == '..') {
                            continue;
                        }
                        if ($access) {
                            array_push($o_out['rufiles'], $ruentry);
                        }
                        if (strrpos($ruentry, '.json') === false) {
                            continue;
                        }
                        if (is_null($rufiles)) {
                            continue;
                        }
                        $found = false;
                        foreach ($rufiles as $rufile) {
                            if (strpos($ruentry, $rufile) === 0) {
                                $found = true;
                                break;
                            }
                        }
                        if (false == $found) {
                            continue;
                        }
                        if ($fHandle = fopen($path . '/' . $ruentry, 'r')) {
                            $rudata = fread($fHandle, $FileMaxLength);
                            $ruobj = json_decode($rudata, true);
                            $o_out['rules'][$ruentry] = $ruobj;
                            fclose($fHandle);
                        }
                    }
                    closedir($rHandle);
                    sort($o_out['rufiles']);
                    ksort($o_out['rules']);
                }
                continue;
            }
            if ($i_recv['showhidden'] == false && is_file("{$path}/.hidden")) {
                continue;
            }
            if ($denied) {
                continue;
            }
            if (false === htaccessFolder($path)) {
                continue;
            }
            $folderObj = array();
            if (is_array($walk)) {
                if (array_key_exists('folders', $walk)) {
                    if (array_key_exists($entry, $walk['folders'])) {
                        $folderObj = $walk['folders'][$entry];
                    }
                }
            }
            $folderObj['name'] = $entry;
            $folderObj['mtime'] = filemtime($path);
            if ($rufolder && $lookahead) {
                foreach ($lookahead as $sfile) {
                    $sfilepath = $path . '/' . $rufolder . '/' . $sfile . '.json';
                    if (is_file($sfilepath)) {
                        if ($fHandle = fopen($sfilepath, 'r')) {
                            $data = fread($fHandle, $FileMaxLength);
                            fclose($fHandle);
                            mergeObjs($folderObj, json_decode($data, true));
                        }
                    }
                }
            }
            if ($i_depth < $i_recv['depth']) {
                walkDir($i_recv, $path, $folderObj, $i_depth + 1);
            }
            array_push($o_out['folders'], $folderObj);
        }
        closedir($handle);
    }
}