Example #1
0
function list_all_dir($path, &$tree)
{
    if (!is_dir($path)) {
        return false;
    }
    if (!($dir = dir($path))) {
        return false;
    }
    $i = 0;
    while (false !== ($filename = $dir->read())) {
        $t = array();
        if (preg_match("/^(\\.{1,2}|\\.svn)\$/ism", $filename)) {
            continue;
        }
        $filetype = filetype($dir->path . '/' . $filename);
        if ($filetype == 'dir') {
            list_all_dir($dir->path . '/' . $filename, $t['folders']);
        }
        $fileinfo = stat($dir->path . '/' . $filename);
        $pathinfo = pathinfo($filename);
        $t['path'] = urlencode(encrypt(path_clean($dir->path . '/' . $filename)));
        $filename = mb_convert_encoding($filename, "UTF-8", "GBK");
        $t['id'] = $filename . uniqid("_");
        $t['filetype'] = $filetype;
        $t['name'] = $filename;
        $t['basename'] = $pathinfo['basename'];
        $t['extension'] = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';
        $t['time'] = date("Y-m-d H:i:s", $fileinfo['mtime']);
        $t['size'] = $fileinfo['size'];
        $t['dir'] = urlencode(path_clean($dir->path));
        $tree[$i] = $t;
        $i++;
        @array_multisort($tree, SORT_REGULAR, SORT_DESC);
        //排序 如果搜索全部类型则先列数组
    }
    $dir->close();
}
$class_path = '../classes/';
include $class_path . 'port.inc.php';
$site = new Site(array());
// so there would be no parse errors in json
ini_set('display_errors', 0);
// generate alias
if ($site->user->user_id && $_REQUEST['op'] == 'generate_alias' && isset($_REQUEST['string']) && isset($_REQUEST['language_id'])) {
    include_once $class_path . 'adminpage.inc.php';
    $alias = create_alias_for_object($_REQUEST['string'], $_REQUEST['language_id']);
    echo '{"alias": "' . $alias . '"}';
    exit;
}
// check if a file exists
if ($site->user->user_id && $_REQUEST['op'] == 'check_file' && $site->fdat['name']) {
    include_once $class_path . 'adminpage.inc.php';
    if ($pathinfo = path_clean($site->fdat['name'])) {
        $pathinfo = explode('/', $pathinfo);
        $filename = create_alias_from_string($pathinfo[count($pathinfo) - 1], true);
        unset($pathinfo[count($pathinfo) - 1]);
        $dirname = implode('/', $pathinfo);
        if (file_exists($site->absolute_path . $dirname . '/' . $filename)) {
            echo '{"file_exists": 1}';
        } else {
            echo '{"file_exists": 0}';
        }
    } else {
        echo '{"file_exists": 0}';
    }
    exit;
}
// get subfolders