Exemple #1
0
/**
 * This could go into the File class, but then how would Env be able to find
 * File.php?
 */
function searchDir($class, $dirname, $recursive = true)
{
    $dirname = $dirname . '/';
    $dir = dir($dirname);
    $classFile = $dirname . $class . ".php";
    if (file_exists($classFile)) {
        return $classFile;
    }
    while (false !== ($cdir = $dir->read())) {
        if (!preg_match('/^\\./', $cdir)) {
            $node = null;
            if (is_dir($dirname . $cdir) && $recursive == true) {
                $node = searchDir($class, $dirname . $cdir . "/");
            }
            if ($node) {
                return $node;
            }
        }
    }
    $dir->close();
    return false;
}
                    $add = false;
                }
            }
            if ($fName == "..") {
                if ($p == $base_dir) {
                    $add = false;
                } else {
                    $add = true;
                }
                $tempar = explode("/", $fPath);
                array_splice($tempar, -2);
                $fPath = implode("/", $tempar);
                if (strlen($fPath) <= strlen($base_dir)) {
                    $fPath = "";
                }
            }
        }
        if ($fPath != "") {
            $fPath = substr($fPath, strlen($base_dir));
        }
        if ($add) {
            $contents[] = array("fPath" => $fPath, "fName" => $fName, "fType" => $fType);
        }
    }
    $p = strlen($p) <= strlen($base_dir) ? $p = "" : substr($p, strlen($base_dir));
    return array("contents" => $contents, "currentPath" => $p);
}
$p = isset($_POST["path"]) ? $_POST["path"] : "";
$f = isset($_POST["filter"]) ? $_POST["filter"] : "";
echo json_encode(searchDir("./", $p, $f, -1));
Exemple #3
0
 static function getDir($dir)
 {
     $data = array();
     searchDir($dir, $data);
     return $data;
 }
Exemple #4
0
function getDir($dir, $prefix = false)
{
    $data = array();
    searchDir($dir, $data, $prefix);
    return $data;
}
function getAllFiles($dir)
{
    $data = array();
    searchDir($dir, "", $data);
    return $data;
}