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