public function browse($dir = "") { if (!is_dir(Setting::get('repo.path'))) { mkdir(Setting::get('repo.path')); } $originaldir = $dir; $isRelativePath = false; if ($dir == "" || $dir == DIRECTORY_SEPARATOR) { $dir = $this->repoPath; $parent = ""; } else { if (strpos($this->repoPath, $dir) === 0) { $isRelativePath = true; } $dir = $this->repoPath . DIRECTORY_SEPARATOR . trim($dir, DIRECTORY_SEPARATOR); $parent = dirname($dir); } if (!realpath($dir) && $isRelativePath) { $dir = getcwd() . DIRECTORY_SEPARATOR . $dir; } $list = []; if (!is_dir($dir)) { if (RepoManager::getModuleDir() == $originaldir) { mkdir($dir); } else { return false; } } ## listing dir $list = []; if ($handle = opendir($dir)) { $count = 0; while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $path = RepoManager::resolve($dir . DIRECTORY_SEPARATOR . $entry); $perm = RepoManager::getPerms($path); $size = filesize($path); $path = $this->relativePath($dir . DIRECTORY_SEPARATOR . $entry); $path = substr($path, strlen($this->repoPath)); $list[] = ['name' => $entry, 'type' => $perm[0] == 'd' ? "dir" : "." . substr($entry, strrpos($entry, '.') + 1), 'size' => $size, 'downloadPath' => base64_encode($path), 'path' => $path]; $count++; } } closedir($handle); } usort($list, ['RepoManager', 'sortItem']); $count = count($list); if ($originaldir != "" && $originaldir != RepoManager::getModuleDir()) { $parent = $this->relativePath($parent); $parent = substr($parent, strlen($this->repoPath)); } else { $parent = ""; } $detail = ['parent' => $parent, 'path' => $this->relativePath($dir), 'type' => 'dir', 'item' => $list, 'count' => $count]; return $detail; }