public static function real($path) { $path = Path::split($path); $newpath = array(); while (list(, $v) = each($path)) { switch ($v) { case '.': continue; case '..': array_pop($newpath); continue; default: $newpath[] = $v; } } return Path::join($newpath); }
function searchFiles($path, $name, $content) { if ($name === '' && $content === '') { throw new NameException(); } $parent = $this->rootFolder; if ($parent->isProxy) { if ($parent->canSearch) { return $parent->searchFiles($path, $name, $content); } return []; } $splitPaths = Path::split($path); $passedFolders = []; while ($splitPaths) { $folderName = array_shift($splitPaths); $passedFolders[] = $folderName; $item = $parent->get($folderName); if (!$item) { throw new FolderNotFoundException(Path::join($passedFolders)); } else { if ($item instanceof File) { throw new NotAFolderException($path); } elseif ($item->isProxy) { if ($item->canSearch) { $files = $item->searchFiles(Path::join($splitPaths), $name, $content); foreach ($files as &$file) { $file['path'] = Path::join([$path, $file['path']]); } return $files; } throw new NotAFolderException(Path::join($passedFolders)); } } $parent = $item; } $files = $parent->searchFiles($name, $content); foreach ($files as &$file) { $file['path'] = Path::join([$path, $file['path']]); } return $files; }
function searchFiles($path, $name, $content) { $splitPaths = Path::split($path); $this->chdir($splitPaths); $files = $this->searchFilesRecursive($name, $content, []); foreach ($files as &$file) { $file['path'] = Path::join([$path, $file['path']]); } return $files; }
function remove($path) { $this->sessionSuspend(); try { $ftp = $this->getConnection(); $splitPaths = Path::split($path); $name = array_pop($splitPaths); $this->chdir($ftp, $splitPaths); if (ftp_is_dir($ftp, $name)) { include_once __DIR__ . '/../fns/ftp_rrmdir.php'; $ok = ftp_rrmdir($ftp, $name); if (!$ok) { throw new ReadWriteException($path); } } elseif (ftp_is_file($ftp, $name)) { $ok = @ftp_delete($ftp, $name); if (!$ok) { throw new ReadWriteException($path); } } else { throw new FileNotFoundException($path); } } catch (Exception $e) { $this->sessionResume(); throw $e; } $this->sessionResume(); }
$items = $index['items']; if ($items) { foreach ($items as $item) { $name = $href = $item['name']; $type = $item['type']; if ($type == 'parent-folder') { $href = '..'; $name = '.. Parent Folder'; } elseif ($type == 'folder') { $href .= '/'; $name .= '/'; } $html .= '<div>' . '<a href="' . htmlspecialchars($href) . '">' . htmlspecialchars($name) . '</a>' . '</div>'; } } else { $html .= '<div style="color: #474740">Folder is empty.</div>'; } $html .= '</body>' . '</html>'; echo $html; } else { $splitPath = Path::split($path); $folderName = array_pop($splitPath); redirect("{$folderName}/"); } } } catch (FolderNotFoundException $e) { header('HTTP/1.1 404 Not Found'); echo '<!DOCTYPE html>' . '<html>' . '<head>' . '<title>404 Not Found</title>' . '</head>' . '<body>' . '<h1>404 Not Found</h1>' . '</body>' . '</html>'; } catch (FileSystemException $e) { $e->echoClientJson(); }