Esempio n. 1
0
function clearPath($path)
{
    @chmod($path, 0777);
    if (@is_dir($path)) {
        if (($dh = @opendir($path)) !== false) {
            while (($file = readdir($dh)) !== false) {
                if (strcmp($file, '.') !== 0 && strcmp($file, '..') !== 0) {
                    if (!clearPath($path . '/' . $file)) {
                        return false;
                    }
                }
            }
            @closedir($dh);
        }
        if (!@rmdir($path)) {
            return false;
        }
    } else {
        if (is_file($path)) {
            if (!@unlink($path)) {
                return false;
            }
        }
    }
    return true;
}
Esempio n. 2
0
function scanLocal($dir, $rootLength = null)
{
    $dir = clearPath($dir);
    if (is_null($rootLength)) {
        $rootLength = strlen($dir);
    }
    // check whether $root is a valid directory
    if (!is_dir($dir)) {
        echo "{$dir} is not a valid directory\n";
        die;
    }
    //scan dir, create file modification time view
    $files = array();
    $curDirList = scandir($dir);
    foreach ($curDirList as $n) {
        if ($n[0] == '.') {
            continue;
        }
        // jump the hidden directory and file
        $n = $dir . $n;
        $fileName = substr($n, $rootLength);
        $files[$fileName] = filemtime($n);
        if (is_dir($n)) {
            $files = array_merge($files, scanLocal($n, $rootLength));
        }
    }
    return $files;
}