Ejemplo n.º 1
0
 public function getMimeType()
 {
     if ($this->mimeType === null) {
         $this->mimeType = FileUtils::getMimeType($this->absolutePath);
     }
     return $this->mimeType;
 }
 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);
 }