當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。