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


PHP File::guessExtension方法代码示例

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


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

示例1: preUpload

 public function preUpload()
 {
     if (null !== $this->photo_file) {
         // do whatever you want to generate a unique name
         $this->nom = $this->getUser()->getUsername() . '.' . $this->photo_file->guessExtension();
     }
 }
开发者ID:luciemannechez,项目名称:projet-intranet_hopital,代码行数:7,代码来源:Photo.php

示例2: preUpload

 public function preUpload()
 {
     if (null !== $this->file) {
         // do whatever you want to generate a unique name
         $this->file_name = $this->file->getClientOriginalName();
         $this->charte_file = uniqid() . '.' . $this->file->guessExtension();
     }
 }
开发者ID:luciemannechez,项目名称:projet-intranet_hopital,代码行数:8,代码来源:Charte.php

示例3: testGuessExtensionWithReset

 /**
  * @requires extension fileinfo
  */
 public function testGuessExtensionWithReset()
 {
     $file = new File(__DIR__ . '/Fixtures/other-file.example');
     $guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
     MimeTypeGuesser::getInstance()->register($guesser);
     $this->assertEquals('gif', $file->guessExtension());
     MimeTypeGuesser::reset();
     $this->assertNull($file->guessExtension());
 }
开发者ID:saj696,项目名称:pipe,代码行数:12,代码来源:FileTest.php

示例4: upload

 /**
  * @throws FileException
  */
 public function upload()
 {
     if ($this->file instanceof File) {
         $name = sha1($this->file->getClientOriginalName() . uniqid() . getrandmax()) . '.' . $this->file->guessExtension();
         $this->file->move($this->getWeb() . $this->folder, $name);
         $this->file = $name;
     } else {
         throw new FileException('It must be a Symfony\\Component\\HttpFoundation\\File\\File instance');
     }
 }
开发者ID:radmar,项目名称:RedactorBundle,代码行数:13,代码来源:Resource.php

示例5: testGuessExtensionIsBasedOnMimeType

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

示例6: generateRelativePath

 /**
  * @param Contribution $contribution
  * @param File         $file
  *
  * @return string
  */
 public function generateRelativePath(Contribution $contribution, File $file)
 {
     $path = $contribution->getAuthProvider() . DIRECTORY_SEPARATOR;
     $path .= $contribution->getIdentifier();
     $path .= '.' . ($file->guessExtension() ?: $file->getExtension());
     return $path;
 }
开发者ID:rcambien,项目名称:haphpy-birthday,代码行数:13,代码来源:PathGenerator.php

示例7: regenerateSpeakerPhotoPath

 private function regenerateSpeakerPhotoPath($speaker)
 {
     // If speaker photo does not exist, null it out and return.
     if (!$this->fileExists($speaker['photo_path'])) {
         echo "[info] {$speaker['name']}'s photo was not found in file system. Removing record of it from profile." . PHP_EOL;
         $this->execute("UPDATE users SET photo_path = '' WHERE id = {$speaker['id']}");
         return;
     }
     // Need to guess extension. Cannot trust current file extensions.
     $file = new File(__DIR__ . '/../web/uploads/' . $speaker['photo_path']);
     $extension = $file->guessExtension();
     // Otherwise, generate a new filename.
     $generator = new PseudoRandomStringGenerator(new Factory());
     $newFileName = $generator->generate(40) . '.' . $extension;
     $oldFilePath = __DIR__ . '/../web/uploads/' . $speaker['photo_path'];
     $newFilePath = __DIR__ . '/../web/uploads/' . $newFileName;
     // If photo name is changed in file system, update record in database.
     if (rename($oldFilePath, $newFilePath)) {
         try {
             $this->execute("UPDATE users SET photo_path = '{$newFileName}' WHERE id = '{$speaker['id']}'");
             echo "[info] Regenerated photo path for {$speaker['name']}." . PHP_EOL;
         } catch (\Exception $e) {
             // If update fails for any reason, revert filename in file system.
             rename($newFilePath, $oldFilePath);
         }
     }
 }
开发者ID:noahd1,项目名称:opencfp,代码行数:27,代码来源:20150519122926_reset_photo_paths.php

示例8: upload

 /**
  * Handles image upload and resize
  *
  * @param string $context
  * @param File $uploadedFile
  * @param string $fileName
  * @param bool $useHashAsFilename
  *
  * @return string
  */
 public function upload($context, File $uploadedFile, $fileName = null, $useHashAsFilename = null)
 {
     if (null === $useHashAsFilename) {
         $useHashAsFilename = $this->config['use_hash_as_image_name'];
     }
     $contextPath = $this->config['base_path'] . '/' . $context;
     if (true === $useHashAsFilename) {
         $fileName = $this->generateHash();
     }
     $fileName .= '.' . $uploadedFile->guessExtension();
     if ($this->filesystem->exists($contextPath . '/' . $fileName) && true === $useHashAsFilename) {
         $this->upload($contextPath, $uploadedFile, $fileName, $useHashAsFilename);
     } elseif ($this->filesystem->exists($contextPath . '/' . $fileName) && false === $useHashAsFilename) {
         throw new IcrLogicException("File {$fileName} exists! Please choose another name!");
     }
     // Upload original file
     $this->filesystem->dumpFile($contextPath . '/' . $fileName, file_get_contents($uploadedFile->getRealPath()));
     foreach ($this->config['contexts'][$context] as $sizeName => $values) {
         // Process and manipulate
         $manipulator = $this->manipulatorFactory->create($values['operation']);
         $abstractImage = $this->openImageHandler->openImage($uploadedFile->getPathname());
         $image = $manipulator->manipulate($abstractImage, $values['width'], $values['height']);
         $path = $contextPath . '/' . $sizeName . '/';
         $this->filesystem->dumpFile($path . '/' . $fileName, $image);
     }
     return $fileName;
 }
开发者ID:todstoychev,项目名称:icr-bundle,代码行数:37,代码来源:Icr.php

示例9: getExtension

 /**
  * Use Symfony components to guess the file extension.
  *
  * @return string
  *         File extension
  */
 public function getExtension()
 {
     if (!is_null($this->extension)) {
         return $this->extension;
     }
     return $this->extension = $this->info->getExtension() ?: $this->info->guessExtension();
 }
开发者ID:fuzz-productions,项目名称:image-resizer,代码行数:13,代码来源:File.php

示例10: setFile

 /**
  * @param File $file
  *
  * @return $this
  */
 public function setFile(File $file)
 {
     $this->file = $file;
     if ($file->getPathname()) {
         $this->filename = sha1(uniqid(mt_rand(), true)) . '.' . $file->guessExtension();
     }
     return $this;
 }
开发者ID:ranpafin,项目名称:docty,代码行数:13,代码来源:SimpleFile.php

示例11: preUpload

 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if (null !== $this->file) {
         $filename = sha1(uniqid(mt_rand(), true));
         $this->path = $filename . '.' . $this->file->guessExtension();
         $this->name = $this->getFile()->getClientOriginalName();
     }
 }
开发者ID:alexandr-kalenyuk,项目名称:levi9voter,代码行数:12,代码来源:Image.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: updateImage

 /**
  * @param \Exolnet\Image\Image                        $image
  * @param \Symfony\Component\HttpFoundation\File\File $file
  */
 public function updateImage(Image $image, File $file)
 {
     $this->destroy($image);
     $fileName = $image->getId() . '-' . Str::slug($file->getBasename()) . '.' . $file->guessExtension();
     $image->setFilename($fileName);
     $image->save();
     $this->store($image, $file);
 }
开发者ID:eXolnet,项目名称:laravel-image,代码行数:12,代码来源:ImageService.php

示例14: moveFile

 /**
  * @param File $image
  * @param string $prefix
  * @param String $path
  * @return string
  */
 public function moveFile(File $image, $path, $prefix = '')
 {
     $extension = $image->guessExtension();
     $code = strtoupper($this->request->get('code'));
     $fileName = $code . '-' . $prefix . '.' . $extension;
     $image->move(public_path() . $path, $fileName);
     return $path . $fileName;
 }
开发者ID:SkysoulDesign,项目名称:mirage.dev,代码行数:14,代码来源:CreateProductJob.php

示例15: image64

 /**
  * Transform image to base 64
  * @param  string $path relative path to image from bundle directory
  * @return string       base64 encoded image
  */
 public function image64($path)
 {
     $file = new File($path, false);
     if (!$file->isFile() || 0 !== strpos($file->getMimeType(), 'image/')) {
         return;
     }
     $binary = file_get_contents($path);
     return sprintf('data:image/%s;base64,%s', $file->guessExtension(), base64_encode($binary));
 }
开发者ID:infinitedevelopers,项目名称:base64bundle,代码行数:14,代码来源:ImageExtension.php


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