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


PHP UploadedFile::getMimeType方法代码示例

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


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

示例1: orientate

 /**
  * Orientate the image.
  *
  * @param UploadedFile $file
  * @param              $orientation
  * @return UploadedFile
  */
 protected function orientate(UploadedFile $file, $orientation)
 {
     $image = imagecreatefromjpeg($file->getRealPath());
     switch ($orientation) {
         case 2:
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 3:
             $image = imagerotate($image, 180, 0);
             break;
         case 4:
             $image = imagerotate($image, 180, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 5:
             $image = imagerotate($image, -90, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 6:
             $image = imagerotate($image, -90, 0);
             break;
         case 7:
             $image = imagerotate($image, 90, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 8:
             $image = imagerotate($image, 90, 0);
             break;
     }
     imagejpeg($image, $file->getRealPath(), 90);
     return new UploadedFile($file->getRealPath(), $file->getClientOriginalName(), $file->getMimeType(), $file->getSize());
 }
开发者ID:AkibaTech,项目名称:files-module,代码行数:39,代码来源:FileRotator.php

示例2: upload

 public static function upload(UploadedFile $file, $bucketName)
 {
     if (!$file->isValid()) {
         throw new \Exception(trans('validation.invalid_file'));
     }
     $bucket = Bucket::find($bucketName);
     if (!empty($bucket->mimeTypes()) && !in_array($file->getMimeType(), $bucket->mimeTypes())) {
         throw new \Exception(trans('validation.invalid_file_type'));
     }
     if (!empty($bucket->maxSize()) && !in_array($file->getClientSize(), $bucket->maxSize())) {
         throw new \Exception(trans('validation.invalid_file_size'));
     }
     $disk = Storage::disk($bucket->disk());
     $media = Media::create(['mime' => $file->getMimeType(), 'bucket' => $bucketName, 'ext' => $file->guessExtension()]);
     $disk->put($bucket->path() . '/original/' . $media->fileName, File::get($file));
     if (is_array($bucket->resize())) {
         foreach ($bucket->resize() as $name => $size) {
             $temp = tempnam(storage_path('tmp'), 'tmp');
             Image::make(File::get($file))->fit($size[0], $size[1])->save($temp);
             $disk->put($bucket->path() . '/' . $name . '/' . $media->fileName, File::get($temp));
             unlink($temp);
         }
     }
     return $media;
 }
开发者ID:codebreez,项目名称:collejo-core,代码行数:25,代码来源:Uploader.php

示例3: mockStore

 public function mockStore(Picture $pic, UploadedFile $dummy)
 {
     if ($dummy->getMimeType() != 'image/png') {
         throw new \Exception('fail');
     }
     $pic->setStorageKey('123.jpg');
     $pic->setMimeType($dummy->getMimeType());
 }
开发者ID:xtrasmal,项目名称:iinano,代码行数:8,代码来源:PictureTypeTest.php

示例4: upload

 public function upload(UploadedFile $file)
 {
     if (!in_array($file->getMimeType(), $this->allowedMimeTypes)) {
         throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getMimeType()));
     }
     $filename = sprintf('%s/%s/%s/%s.%s', date('Y'), date('m'), date('d'), uniqid(), $file->getClientOriginalExtension());
     $adapter = $this->filesystem->getAdapter();
     $adapter->setMetadata($filename, array('contentType' => $file->getMimeType()));
     $adapter->write($filename, file_get_contents($file->getPathname()));
     return $adapter->getUrl($filename);
 }
开发者ID:scottstuff,项目名称:GCProtractorJS,代码行数:11,代码来源:AbstractUploader.php

示例5: processFile

 /**
  * Process image file, make it progressive
  * @param UploadedFile $file
  */
 public function processFile(UploadedFile $file)
 {
     $this->file = $file;
     foreach (self::$IMAGE_TYPES as $type) {
         if (in_array($this->file->getMimeType(), $type['mime_types'])) {
             $filePath = $this->file->getRealPath();
             $typeObject = new $type['class']($filePath);
             $typeObject->process();
             break;
         }
     }
 }
开发者ID:hellmark1990,项目名称:Test-progressive-image,代码行数:16,代码来源:ProgressiveManager.php

示例6: upload

 /**
  * Upload (move) file to branch logos directory
  * @param UploadedFile $logo
  * @param null|string $targetFilename
  * @return \Symfony\Component\HttpFoundation\File\File
  * @throws LogoHandlerLogicException
  */
 public function upload(UploadedFile $logo, $targetFilename = null)
 {
     if (!in_array($logo->getMimeType(), $this->permittedMimeTypes)) {
         throw new LogoHandlerLogicException(sprintf('"%s" file type is not permitted. Use images for logo and try again.', $logo->getMimeType()));
     }
     if (is_null($targetFilename)) {
         $targetFilename = sha1(uniqid(mt_rand(), true)) . '.' . $logo->guessExtension();
     }
     if (false === $this->branchLogoDir->isDir() || false === $this->branchLogoDir->isWritable()) {
         throw new \RuntimeException(sprintf("Branch logo directory (%s) is not writable, doesn't exist or no space left on the disk.", $this->branchLogoDir->getRealPath()));
     }
     return $logo->move($this->branchLogoDir->getRealPath(), $targetFilename);
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:20,代码来源:BranchLogoHandler.php

示例7: canUpload

 /**
  * {@inheritdoc}
  */
 public function canUpload(UploadedFile $file)
 {
     $mimeType = $file->getMimeType();
     if (in_array($mimeType, $this->getSupportedMimeTypes())) {
         return 5;
     }
     if ($file->getMimeType() == 'application/ogg') {
         // This could be a video or audio file.
         $meta = GenericMetadataReader::readMetadata($file->getPathname());
         if (isset($meta['audio']['dataformat'])) {
             return 5;
         }
     }
     return 0;
 }
开发者ID:shefik,项目名称:MediaModule,代码行数:18,代码来源:Audio.php

示例8: validate

 /**
  * @param UploadedFile $file
  * @param array        $methods
  *
  * @return mixed|void
  *
  * @throws InvalidFileTypeException
  * @throws InvalidFileException
  * @throws UploadFileNotSetException
  * @throws MaxFileSizeExceededException
  */
 public function validate(UploadedFile $file, $methods = [self::VALIDATOR_FILE_SET, self::VALIDATOR_FILE_ERRORS, self::VALIDATOR_BLOCK_FILE_TYPES, self::VALIDATOR_MAX_FILE_SIZE])
 {
     if (in_array(self::VALIDATOR_FILE_ERRORS, $methods) && $file->getError() > 0) {
         throw new InvalidFileException(sprintf('The file upload had an error("%s: %s")', $file->getError(), $file->getErrorMessage()));
     }
     if (in_array(self::VALIDATOR_FILE_SET, $methods) && $file->getFilename() == '') {
         throw new UploadFileNotSetException(sprintf('No file "%s" was set', $file->getFilename()));
     }
     if (in_array(self::VALIDATOR_BLOCK_FILE_TYPES, $methods) && in_array($file->getMimeType(), $this->blockedMimeTypes)) {
         throw new InvalidFileTypeException(sprintf('The file type "%s" was blocked', $file->getMimeType()));
     }
     if (in_array(self::VALIDATOR_MAX_FILE_SIZE, $methods) && $this->maxFileSize !== null && $file->getSize() >= $this->maxFileSize) {
         throw new MaxFileSizeExceededException(sprintf('File "%s" exceeds the configured maximum filesize of "%s"', $file->getFilename(), $this->maxFilesize));
     }
 }
开发者ID:sulu,项目名称:sulu,代码行数:26,代码来源:FileValidator.php

示例9: canUpload

 /**
  * {@inheritdoc}
  */
 public function canUpload(UploadedFile $file)
 {
     if ($file->getMimeType() == 'text/plain' && $file->getClientOriginalExtension() == 'md') {
         return 5;
     }
     return 0;
 }
开发者ID:shefik,项目名称:MediaModule,代码行数:10,代码来源:Markdown.php

示例10: doUpload

 /**
  * {@inheritDoc}
  */
 protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name)
 {
     $fs = $this->getFilesystem($mapping);
     $path = !empty($dir) ? $dir . '/' . $name : $name;
     $stream = fopen($file->getRealPath(), 'r+');
     $fs->writeStream($path, $stream, array('mimetype' => $file->getMimeType()));
 }
开发者ID:czifumasa,项目名称:Inzynierka5,代码行数:10,代码来源:FlysystemStorage.php

示例11: canUpload

 /**
  * {@inheritdoc}
  */
 public function canUpload(UploadedFile $file)
 {
     $mimeType = $file->getMimeType();
     if (in_array($mimeType, $this->getSupportedMimeTypes())) {
         return 4;
     }
     return 0;
 }
开发者ID:shefik,项目名称:MediaModule,代码行数:11,代码来源:Plaintext.php

示例12: createVersionFromFile

 /**
  * @param AssetInterface $asset
  * @param UploadedFile   $file
  *
  * @return AssetVersion
  */
 public function createVersionFromFile(AssetInterface $asset, UploadedFile $file)
 {
     list($width, $height) = getimagesize($file->getRealPath());
     $extension = File::extension($file->getClientOriginalName(), $file->getMimetype());
     $version = $this->version->create(['asset_id' => $asset->getId(), 'extension' => $extension, 'filesize' => $file->getClientSize(), 'filename' => $file->getClientOriginalName(), 'width' => $width, 'height' => $height, 'edited_at' => time(), 'edited_by' => Auth::getPerson()->getId(), 'mimetype' => $file->getMimeType(), 'metadata' => File::exif($file->getRealPath())]);
     $file->move($asset->directory(), $version->id);
     return $version;
 }
开发者ID:robbytaylor,项目名称:boom-core,代码行数:14,代码来源:Asset.php

示例13: testFileUploadsWithNoMimeType

 public function testFileUploadsWithNoMimeType()
 {
     $file = new UploadedFile(__DIR__ . '/Fixtures/test.gif', 'original.gif', null, filesize(__DIR__ . '/Fixtures/test.gif'), UPLOAD_ERR_OK);
     $this->assertEquals('application/octet-stream', $file->getClientMimeType());
     if (extension_loaded('fileinfo')) {
         $this->assertEquals('image/gif', $file->getMimeType());
     }
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:8,代码来源:UploadedFileTest.php

示例14: doUpload

 /**
  * {@inheritDoc}
  */
 protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name)
 {
     $filesystem = $this->getFilesystem($mapping);
     $path = !empty($dir) ? $dir . '/' . $name : $name;
     if ($filesystem->getAdapter() instanceof MetadataSupporter) {
         $filesystem->getAdapter()->setMetadata($path, array('contentType' => $file->getMimeType()));
     }
     $filesystem->write($path, file_get_contents($file->getPathname()), true);
 }
开发者ID:czifumasa,项目名称:Inzynierka5,代码行数:12,代码来源:GaufretteStorage.php

示例15: validate

 /**
  * Checks if the passed value is valid.
  *
  * @param UploadedFile   $file      The value that should be validated
  * @param Constraint     $constraint The constraint for the validation
  */
 public function validate($file, Constraint $constraint)
 {
     if (!in_array($file->getMimeType(), $this->mimeTypes)) {
         $this->context->buildViolation($constraint->messageMimeTypes)->atPath('file')->addViolation();
     }
     if ($file->getSize() > $file->getMaxFilesize()) {
         $this->context->buildViolation($constraint->messageMaxSize, array('%max_size%' => $file->getMaxFilesize()))->atPath('file')->addViolation();
     }
 }
开发者ID:open-orchestra,项目名称:open-orchestra-media-bundle,代码行数:15,代码来源:MediaFileValidator.php


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