public function getIcon() { if ($this->icon === null) { $mimeType = $this->getMimeType(); if ($mimeType === 'directory') { $this->icon = 'fa-folder-open-o'; } elseif (MimeType::isText($mimeType)) { $this->icon = 'fa-file-text-o'; } elseif (MimeType::isImage($mimeType)) { $this->icon = 'fa-file-image-o'; } elseif (MimeType::isAudio($mimeType)) { $this->icon = 'fa-file-audio-o'; } elseif (MimeType::isVideo($mimeType)) { $this->icon = 'fa-file-video-o'; } elseif (MimeType::isPdf($mimeType)) { $this->icon = 'fa-file-pdf-o'; } elseif (MimeType::isArchive($mimeType)) { $this->icon = 'fa-file-archive-o'; } else { $this->icon = 'fa-file-o'; } } return $this->icon; }
protected function displayFile(Request $request, FileManager $fileManager) { if (!$request->query->has('path')) { return $this->abort(400); } $path = $fileManager->getAbsolutePath($request->query->get('path')); if (!is_file($path)) { return $this->abort(404); } $mimeType = FileUtils::getMimeType($path); if (!MimeType::isDisplayable($mimeType)) { return $this->abort(500, 'error.notDisplayable'); } $relativePath = $fileManager->getRelativePath($path); $breadcrumb = self::getBreadcrumb($fileManager, $path, false); $name = pathinfo($relativePath, PATHINFO_BASENAME); $data = ["name" => $name, "breadcrumb" => $breadcrumb]; if (MimeType::isText($mimeType)) { $data["text"] = file_get_contents($path); } elseif (MimeType::isImage($mimeType)) { $data["src"] = $relativePath; } return $this->render($data); }