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::ATOM, $file->getMTime())]);
}
$data['items'][] = $info;
}
return $data;
}