当前位置: 首页>>代码示例>>PHP>>正文


PHP File::getMimeType方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\File::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP File::getMimeType方法的具体用法?PHP File::getMimeType怎么用?PHP File::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\File\File的用法示例。


在下文中一共展示了File::getMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getMimeType

 /**
  * Get mime type of file.
  *
  * @return string
  */
 public function getMimeType()
 {
     if ($this->file instanceof UploadedFile) {
         return $this->file->getClientMimeType();
     }
     return $this->file->getMimeType();
 }
开发者ID:Vooodoo,项目名称:MediaBundle,代码行数:12,代码来源:FileInfo.php

示例2: isValid

 public function isValid($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return true;
     }
     if (!is_scalar($value) && !$value instanceof FileObject && !(is_object($value) && method_exists($value, '__toString()'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     if ($value instanceof FileObject && null === $value->getPath()) {
         return true;
     }
     $path = $value instanceof FileObject ? $value->getPath() : (string) $value;
     if (!file_exists($path)) {
         $this->setMessage($constraint->notFoundMessage, array('{{ file }}' => $path));
         return false;
     }
     if (!is_readable($path)) {
         $this->setMessage($constraint->notReadableMessage, array('{{ file }}' => $path));
         return false;
     }
     if ($constraint->maxSize) {
         if (ctype_digit((string) $constraint->maxSize)) {
             $size = filesize($path);
             $limit = $constraint->maxSize;
             $suffix = ' bytes';
         } else {
             if (preg_match('/^(\\d+)k$/', $constraint->maxSize, $matches)) {
                 $size = round(filesize($path) / 1000, 2);
                 $limit = $matches[1];
                 $suffix = ' kB';
             } else {
                 if (preg_match('/^(\\d+)M$/', $constraint->maxSize, $matches)) {
                     $size = round(filesize($path) / 1000000, 2);
                     $limit = $matches[1];
                     $suffix = ' MB';
                 } else {
                     throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $constraint->maxSize));
                 }
             }
         }
         if ($size > $limit) {
             $this->setMessage($constraint->maxSizeMessage, array('{{ size }}' => $size . $suffix, '{{ limit }}' => $limit . $suffix, '{{ file }}' => $path));
             return false;
         }
     }
     if ($constraint->mimeTypes) {
         if (!$value instanceof FileObject) {
             $value = new FileObject($value);
         }
         if (!in_array($value->getMimeType(), (array) $constraint->mimeTypes)) {
             $this->setMessage($constraint->mimeTypesMessage, array('{{ type }}' => '"' . $value->getMimeType() . '"', '{{ types }}' => '"' . implode('", "', (array) $constraint->mimeTypes) . '"', '{{ file }}' => $path));
             return false;
         }
     }
     return true;
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:56,代码来源:FileValidator.php

示例3: resize

 /**
  * Resize image
  *
  * @param  int $width Thumbnail width
  * @param  int $height Thumbnail height
  * @param  string $fileName Source file name
  * @return \Response Image content
  */
 public function resize($width, $height, $fileName)
 {
     $destFile = $this->createThumb($width, $height, $fileName);
     $fileContent = $this->getFileContent($destFile);
     $file = new SymfonyFile($destFile);
     return response()->make($fileContent, 200, ['content-type' => $file->getMimeType()]);
 }
开发者ID:namnv609,项目名称:l5-fly-thumb,代码行数:15,代码来源:L5FlyThumb.php

示例4: create

 /**
  * @param File $file
  *
  * @return NotImageGivenException
  */
 public static function create(File $file)
 {
     $msg = sprintf('File "%s" is not an image, expected mime type is image/*, given - ', $file->getPathname(), $file->getMimeType());
     $me = new static($msg);
     $me->failedFile = $file;
     return $me;
 }
开发者ID:modera,项目名称:foundation,代码行数:12,代码来源:NotImageGivenException.php

示例5: missingMethod

 /**
  * @param array $parameters
  *
  * @return mixed|void
  */
 public function missingMethod($parameters = array())
 {
     if (is_array($parameters)) {
         $parameters = implode('/', $parameters);
     }
     # If parameters is a file
     if ($file = $this->path($parameters)) {
         $response = \with(new AssetCollection(array(new FileAsset($file))))->dump();
     } elseif ($aParameters = json_decode($parameters, TRUE)) {
         array_walk($aParameters, function (&$item) {
             $item = new FileAsset($this->path($item));
         });
         $response = \with(new AssetCollection($aParameters))->dump();
     }
     if (isset($response)) {
         $headers = array();
         if (preg_match('/.css/i', $parameters)) {
             $headers['Content-Type'] = 'text/css';
         } elseif (preg_match('/.js/i', $parameters)) {
             $headers['Content-Type'] = 'text/javascript';
         } elseif (preg_match('/.html|.htm|.php/i', $parameters)) {
             $headers['Content-Type'] = 'text/html';
         } else {
             $file = new File($file);
             $mime = $file->getMimeType();
             if ($mime) {
                 $headers['Content-Type'] = $mime;
             } else {
                 $headers['Content-Type'] = 'text/html';
             }
         }
         return Response::make($response, 200, $headers);
     }
     return Response::make('', 404);
 }
开发者ID:SerdarSanri,项目名称:arx-core,代码行数:40,代码来源:AssetsController.php

示例6: downloadAction

 /**
  * @Route("/download/{resource}", name="bkstg_resource_download_resource")
  * @ParamConverter("resource", class="BkstgResourceBundle:Resource")
  */
 public function downloadAction(Resource $resource)
 {
     $file = new File($resource->getAbsolutePath());
     $headers = array('Content-Type' => $file->getMimeType(), 'Content-Disposition' => 'attachment; filename="' . $resource->getPath() . '"');
     $filename = $resource->getAbsolutePath();
     return new HttpFoundation\Response(file_get_contents($filename), 200, $headers);
 }
开发者ID:bkstg,项目名称:resource-bundle,代码行数:11,代码来源:ResourceController.php

示例7: createImage

 /**
  * Given a single File, assuming is an image, create a new
  * Image object containing all needed information.
  *
  * This method also persists and flush created entity
  *
  * @param File $file File where to get the image
  *
  * @return ImageInterface Image created
  *
  * @throws InvalidImageException File is not an image
  */
 public function createImage(File $file)
 {
     $fileMime = $file->getMimeType();
     if ('application/octet-stream' === $fileMime) {
         $imageSizeData = getimagesize($file->getPathname());
         $fileMime = $imageSizeData['mime'];
     }
     if (strpos($fileMime, 'image/') !== 0) {
         throw new InvalidImageException();
     }
     $extension = $file->getExtension();
     if (!$extension && $file instanceof UploadedFile) {
         $extension = $file->getClientOriginalExtension();
     }
     /**
      * @var ImageInterface $image
      */
     $image = $this->imageFactory->create();
     if (!isset($imageSizeData)) {
         $imageSizeData = getimagesize($file->getPathname());
     }
     $name = $file->getFilename();
     $image->setWidth($imageSizeData[0])->setHeight($imageSizeData[1])->setContentType($fileMime)->setSize($file->getSize())->setExtension($extension)->setName($name);
     return $image;
 }
开发者ID:pramoddas,项目名称:elcodi,代码行数:37,代码来源:ImageManager.php

示例8: testGetMimeTypeUsesMimeTypeGuessers

 public function testGetMimeTypeUsesMimeTypeGuessers()
 {
     $file = new File(__DIR__ . '/Fixtures/test.gif');
     $guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
     MimeTypeGuesser::getInstance()->register($guesser);
     $this->assertEquals('image/gif', $file->getMimeType());
 }
开发者ID:saj696,项目名称:pipe,代码行数:7,代码来源:FileTest.php

示例9: setFileAttribute

 public function setFileAttribute(\Symfony\Component\HttpFoundation\File\File $file)
 {
     $this->attributes['file'] = $file;
     $this->original_name = $file instanceof UploadedFile ? $file->getClientOriginalName() : $file->getFilename();
     $this->size = $file->getSize();
     $this->content_type = $file->getMimeType();
 }
开发者ID:AniartUA,项目名称:crm,代码行数:7,代码来源:File.php

示例10: testCreateImagesFromApplicationOctetStream

 /**
  * @param $imageFileObject
  * @param $finalMimeType
  *
  * @dataProvider imagesAsOctetStreamProvider
  */
 public function testCreateImagesFromApplicationOctetStream(File $imageFileObject, $finalMimeType)
 {
     $this->assertEquals('application/octet-stream', $imageFileObject->getMimeType());
     $image = $this->imageManager->createImage($imageFileObject);
     $this->assertInstanceOf('Elcodi\\Component\\Media\\Entity\\Interfaces\\ImageInterface', $image);
     $this->assertEquals($finalMimeType, $image->getContentType());
 }
开发者ID:axelvnk,项目名称:elcodi,代码行数:13,代码来源:ImageManagerTest.php

示例11: getResponse

 /**
  * @param Closure $callback
  * @param InterventionRequest $interventionRequest
  * @return Response
  */
 public function getResponse(Closure $callback, InterventionRequest $interventionRequest)
 {
     try {
         $this->cacheFile = new File($this->cacheFilePath);
         $response = new Response(file_get_contents($this->cacheFile->getPathname()), Response::HTTP_OK, ['Content-Type' => $this->cacheFile->getMimeType(), 'Content-Disposition' => 'filename="' . $this->realImage->getFilename() . '"', 'X-Generator-Cached' => true]);
         $response->setLastModified(new \DateTime(date("Y-m-d H:i:s", $this->cacheFile->getMTime())));
     } catch (FileNotFoundException $e) {
         if (is_callable($callback)) {
             $image = $callback($interventionRequest);
             if ($image instanceof Image) {
                 $this->saveImage($image);
                 $this->cacheFile = new File($this->cacheFilePath);
                 if (null !== $this->dispatcher) {
                     // create the ImageSavedEvent and dispatch it
                     $event = new ImageSavedEvent($image, $this->cacheFile);
                     $this->dispatcher->dispatch(ImageSavedEvent::NAME, $event);
                 }
                 // send HTTP header and output image data
                 $response = new Response(file_get_contents($this->cacheFile->getPathname()), Response::HTTP_OK, ['Content-Type' => $image->mime(), 'Content-Disposition' => 'filename="' . $this->realImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
                 $response->setLastModified(new \DateTime('now'));
             } else {
                 throw new \RuntimeException("Image is not a valid InterventionImage instance.", 1);
             }
         } else {
             throw new \RuntimeException("No image handle closure defined", 1);
         }
     }
     $this->initializeGarbageCollection();
     return $response;
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:35,代码来源:FileCache.php

示例12: thumb

 public function thumb(Request $request, $id)
 {
     $photo = Photo::findOrFail($id);
     $file = new File($photo->path);
     $photo->makeThumbnail();
     $headers = array('Content-Type: ' . $file->getMimeType());
     return response()->download($photo->path . '.' . $file->guessExtension(), $photo->name, $headers);
 }
开发者ID:pitchinnate,项目名称:photoshare,代码行数:8,代码来源:PhotoController.php

示例13: getMimeType

 /**
  * Returns the mime type of the file.
  *
  * The mime type is guessed using the functions finfo(), mime_content_type()
  * and the system binary "file" (in this order), depending on which of those
  * is available on the current operating system.
  *
  * @returns string  The guessed mime type, e.g. "application/pdf"
  */
 public function getMimeType()
 {
     $mimeType = parent::getMimeType();
     if (null === $mimeType) {
         $mimeType = $this->mimeType;
     }
     return $mimeType;
 }
开发者ID:spf13,项目名称:symfony,代码行数:17,代码来源:UploadedFile.php

示例14: __construct

 /**
  * Constructor.
  *
  * @param File $file A File instance
  */
 public function __construct(File $file)
 {
     if ($file instanceof UploadedFile) {
         parent::__construct($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true);
     } else {
         parent::__construct($file->getPathname(), $file->getBasename(), $file->getMimeType(), $file->getSize(), 0, true);
     }
 }
开发者ID:sfblaauw,项目名称:pulsar-uploader,代码行数:13,代码来源:FilesystemFile.php

示例15: getMimeType

 /**
  * Returns the mime type of the file.
  *
  * The mime type is guessed using the functions finfo(), mime_content_type()
  * and the system binary "file" (in this order), depending on which of those
  * is available on the current operating system.
  *
  * @returns string  The guessed mime type, e.g. "application/pdf"
  */
 public function getMimeType()
 {
     $mimeType = parent::getMimeType();
     if (is_null($mimeType)) {
         $mimeType = $this->mimeType;
     }
     return $mimeType;
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:17,代码来源:UploadedFile.php


注:本文中的Symfony\Component\HttpFoundation\File\File::getMimeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。