예제 #1
0
 public function isDisplayable()
 {
     if ($this->displayable === null) {
         $this->displayable = MimeType::isDisplayable($this->getMimeType());
     }
     return $this->displayable;
 }
 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);
 }