當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Filesystem::mimeType方法代碼示例

本文整理匯總了PHP中Gaufrette\Filesystem::mimeType方法的典型用法代碼示例。如果您正苦於以下問題:PHP Filesystem::mimeType方法的具體用法?PHP Filesystem::mimeType怎麽用?PHP Filesystem::mimeType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Gaufrette\Filesystem的用法示例。


在下文中一共展示了Filesystem::mimeType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: showAction

 /**
  * @param Request $request
  * @param string  $filename
  *
  * @throws NotFoundHttpException If media is not found
  *
  * @return Response
  */
 public function showAction(Request $request, $filename)
 {
     if (!$this->filesystem->has($filename)) {
         throw new NotFoundHttpException(sprintf('Media "%s" not found', $filename));
     }
     $response = new Response($content = $this->filesystem->read($filename));
     $mime = $this->filesystem->mimeType($filename);
     if (($filter = $request->query->get('filter')) && null !== $mime && 0 === strpos($mime, 'image')) {
         try {
             $cachePath = $this->cacheManager->resolve($request, $filename, $filter);
             if ($cachePath instanceof Response) {
                 $response = $cachePath;
             } else {
                 $image = $this->imagine->load($content);
                 $response = $this->filterManager->get($request, $filter, $image, $filename);
                 $response = $this->cacheManager->store($response, $cachePath, $filter);
             }
         } catch (\RuntimeException $e) {
             if (0 === strpos($e->getMessage(), 'Filter not defined')) {
                 throw new HttpException(404, sprintf('The filter "%s" cannot be found', $filter), $e);
             }
             throw $e;
         }
     }
     if ($mime) {
         $response->headers->set('Content-Type', $mime);
     }
     return $response;
 }
開發者ID:jacko972,項目名稱:pim-community-dev,代碼行數:37,代碼來源:MediaController.php

示例2: load

 /**
  * {@inheritDoc}
  */
 public function load($path)
 {
     try {
         $contents = $this->filesystem->read($path);
     } catch (FileNotFoundException $e) {
         throw new Exception\ImageNotFoundException(sprintf('Source image not found in "%s"', $path));
     }
     try {
         $mimeType = $this->filesystem->mimeType($path);
     } catch (\LogicException $e) {
         // Mime Type could not be detected
         return $contents;
     }
     if (!$mimeType) {
         // Mime Type could not be detected
         return $contents;
     }
     return new Binary($contents, $mimeType);
 }
開發者ID:shitikovkirill,項目名稱:zend-shop.com,代碼行數:22,代碼來源:GaufretteLoader.php

示例3: createFromFilename

 /**
  * Create a media and load file information
  *
  * @param string $filename
  * @param bool   $isUploaded
  *
  * @throws \InvalidArgumentException When file does not exist
  *
  * @return ProductMediaInterface
  */
 public function createFromFilename($filename, $isUploaded = true)
 {
     if ($isUploaded) {
         $filePath = $this->uploadDirectory . DIRECTORY_SEPARATOR . $filename;
     } else {
         $filePath = $filename;
     }
     if ($isUploaded && !$this->filesystem->has($filename)) {
         throw new \InvalidArgumentException(sprintf('File "%s" does not exist', $filePath));
     }
     $media = $this->factory->createMedia();
     $media->setOriginalFilename(basename($filename));
     $media->setFilename($filename);
     if (!$isUploaded) {
         $media->setFile(new File($filename));
     } else {
         $media->setMimeType($this->filesystem->mimeType($filename));
     }
     return $media;
 }
開發者ID:jacko972,項目名稱:pim-community-dev,代碼行數:30,代碼來源:MediaManager.php


注:本文中的Gaufrette\Filesystem::mimeType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。