/** * @Request({"path"}) */ public function indexAction($path) { if (!($dir = $this->getPath())) { return $this->error(__('Invalid path.')); } if (!is_dir($dir) || '-' === ($mode = $this->getMode($dir))) { throw new ForbiddenException(__('Permission denied.')); } $data = array_fill_keys(['items'], []); $data['mode'] = $mode; $finder = App::finder(); $finder->sort(function ($a, $b) { return $b->getRealpath() > $a->getRealpath() ? -1 : 1; }); foreach ($finder->depth(0)->in($dir) as $file) { if ('-' === ($mode = $this->getMode($file->getPathname()))) { continue; } $info = ['name' => $file->getFilename(), 'mime' => 'application/' . ($file->isDir() ? 'folder' : 'file'), 'path' => $this->normalizePath($path . '/' . $file->getFilename()), 'url' => ltrim(App::url()->getStatic($file->getPathname(), [], 'base'), '/'), 'writable' => $mode == 'w']; if (!$file->isDir()) { $info = array_merge($info, ['size' => $this->formatFileSize($file->getSize()), 'lastmodified' => date(\DateTime::ISO8601, $file->getMTime())]); } $data['items'][] = $info; } return $data; }
/** * Gets a list of files and directories and their writable status. * * @return string[] */ protected function getDirectories() { // -TODO- $directories = [App::get('path.storage'), App::get('path.temp'), App::get('config.file')]; $result = []; foreach ($directories as $directory) { $result[$this->getRelativePath($directory)] = is_writable($directory); if (is_dir($directory)) { foreach (App::finder()->in($directory)->directories()->depth(0) as $dir) { $result[$this->getRelativePath($dir->getPathname())] = is_writable($dir->getPathname()); } } } return $result; }
/** * TODO: clear opcache */ public function doClearCache(array $options = []) { // clear cache if (empty($options) || @$options['cache']) { App::cache()->flushAll(); foreach (glob(App::get('path.cache') . '/*.cache') as $file) { @unlink($file); } } // clear temp folder if (@$options['temp']) { foreach (App::finder()->in(App::get('path.temp'))->depth(0)->ignoreDotFiles(true) as $file) { App::file()->delete($file->getPathname()); } } }