当前位置: 首页>>代码示例>>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;未经允许,请勿转载。