當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UploadedFile::guessExtension方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::guessExtension方法的典型用法代碼示例。如果您正苦於以下問題:PHP UploadedFile::guessExtension方法的具體用法?PHP UploadedFile::guessExtension怎麽用?PHP UploadedFile::guessExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpFoundation\File\UploadedFile的用法示例。


在下文中一共展示了UploadedFile::guessExtension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handle

 /**
  * Execute the job.
  */
 public function handle()
 {
     /**
      * Create Extra
      * @var Extra $extra
      */
     $extra = $this->product->extras()->create($this->data);
     $aspectDir = @$this->data['aspect_ratio'] ?: '16x9';
     /**
      * Move Extra Content to folder
      */
     $path = '/image/products-extras/';
     $extraID = $extra->getAttribute('id');
     $productCode = $this->product->getAttribute('code');
     $filename = $productCode . '-extra-image-' . $extraID . '.' . $this->image->guessExtension();
     $image = $this->image->move(base_path() . $path, $filename);
     $extra->setAttribute('image', $path . $filename);
     $filename = $productCode . '-extra-video-' . $extraID . '.' . $this->video->guessExtension();
     $video = $this->video->move(base_path() . $path . $aspectDir . '/', $filename);
     $extra->setAttribute('video', $filename);
     $extra->save();
     /**
      * Announce ExtraWasCreated
      */
     event(new ExtraWasCreated($extra));
 }
開發者ID:SkysoulDesign,項目名稱:mirage.dev,代碼行數:29,代碼來源:CreateExtraJob.php

示例2: preUpload

 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if (null === $this->file) {
         return;
     }
     $this->url = $this->file->guessExtension();
     $this->alt = $this->file->getClientOriginalName();
 }
開發者ID:AlexandreRozier,項目名稱:Symfony,代碼行數:12,代碼來源:Image.php

示例3: preUpload

 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     // Si jamais il n'y a pas de fichier (champ facultatif)
     if (null === $this->file) {
         return;
     }
     // Le nom du fichier est son id, on doit juste stocker �galement son extension
     // Pour faire propre, on devrait renommer cet attribut en � extension �, plut�t que � extension �
     $this->extension = $this->file->guessExtension();
     // Et on g�n�re l'attribut alt de la balise <img>, � la valeur du nom du fichier sur le PC de l'internaute
     $this->alt = $this->file->getClientOriginalName();
 }
開發者ID:messi1983,項目名稱:messi-repo,代碼行數:16,代碼來源:Image.php

示例4: preUpload

 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     //        if (null !== $this->getFile()) {
     //            // do whatever you want to generate a unique name
     //            $filename   = sha1(uniqid(mt_rand(), true));
     //            $this->path = $filename.'.'.$this->getFile()->guessExtension();
     //        }
     if (null !== $this->file) {
         // faites ce que vous voulez pour générer un nom unique
         $this->path = sha1(uniqid(mt_rand(), true)) . '.' . $this->file->guessExtension();
     }
 }
開發者ID:CeNeosoftBordeauxLimoges,項目名稱:SiteCe,代碼行數:16,代碼來源:Media.php

示例5: validateFile

 /**
  * Determines whether a passed photo file
  * is valid.
  * @throws  InalidMediaTypeException If the file extension isn't jpeg, jpg, png, bmp or gif
  *
  * @param  Symfony\Component\HttpFoundation\File\UploadedFile   $file
  * @return boolean
  */
 public function validateFile(File $file)
 {
     // if ( ! $file->isValid())
     // {
     //     throw new PhotoUploadException('error occured while uploading photo' , $file->getError());
     // }
     $input = ['extension' => $file->guessExtension()];
     $rules = ['extension' => 'in:jpeg,jpg,png,bmp,gif'];
     $validation = $this->validator->make($input, $rules);
     if ($validation->fails()) {
         throw new InvalidMediaTypeException($file->guessExtension());
     }
     return true;
 }
開發者ID:adibhanna,項目名稱:agency,代碼行數:22,代碼來源:UploadedPhotoValidator.php

示例6: copyFile

 /**
  * Make 3 copy from original user avatar with compression: small, medium and big
  * @param iUser $user
  */
 public function copyFile(iUser $user)
 {
     // move file to original folder
     $upload = $this->file->move(root . '/upload/user/avatar/original/', $user->id . '.' . $this->file->guessExtension());
     try {
         // big image
         $this->resizeAndSave($upload, $user->id, 'big');
         $this->resizeAndSave($upload, $user->id, 'medium');
         $this->resizeAndSave($upload, $user->id, 'small');
     } catch (\Exception $e) {
         if (App::$Debug) {
             App::$Debug->addException($e);
         }
     }
 }
開發者ID:phpffcms,項目名稱:ffcms,代碼行數:19,代碼來源:FormAvatarUpload.php

示例7: getFileMd5Name

 public function getFileMd5Name(UploadedFile $file)
 {
     $ext = $file->guessExtension();
     $md5 = md5_file($file->getRealPath());
     $name = $md5 . '.' . $ext;
     return $name;
 }
開發者ID:wucdbm,項目名稱:gallery-bundle,代碼行數:7,代碼來源:ImageManager.php

示例8: uploadPhoto

 /**
  * @param UploadedFile $file
  * @param Photo        $photo
  */
 public function uploadPhoto(UploadedFile $file, Photo &$photo)
 {
     $fileName = time() . '.' . $file->guessExtension();
     $file->move($this->getUploadDir(), $fileName);
     $photo->setName($fileName);
     $photo->setOriginalName($file->getClientOriginalName());
 }
開發者ID:alexey-wild,項目名稱:stfalcon-photos-api,代碼行數:11,代碼來源:PhotoManager.php

示例9: 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

示例10: preUpload

 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if (null !== $this->file) {
         $name = preg_replace('/([^a-z0-9\\-\\_])/i', '', $this->getName());
         $this->setPath($this->getUploadDir() . '/' . $name . time() . '.' . $this->file->guessExtension());
     }
 }
開發者ID:Gladhon,項目名稱:IbrowsSimpleCMSBundle,代碼行數:11,代碼來源:ImageContent.php

示例11: upload

 /**
  * @param UploadedFile $uploadedFile
  */
 function upload(UploadedFile $uploadedFile)
 {
     $path = sha1(uniqid(mt_rand(), true)) . '.' . $uploadedFile->guessExtension();
     $this->setPath($path);
     $this->setName($uploadedFile->getClientOriginalName());
     $uploadedFile->move($this->getUploadRootDir(), $path);
 }
開發者ID:alexseif,項目名稱:miniERP,代碼行數:10,代碼來源:OrderDocuments.php

示例12: moveUploadedFile

 public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath)
 {
     $originalName = $file->getFilename() . '.' . $file->guessExtension();
     $targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
     $targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
     $ext = $file->getExtension();
     $i = 1;
     while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
         if ($ext) {
             $prev = $i == 1 ? "" : $i;
             $targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
         } else {
             $targetFilePath = $targetFilePath . $i++;
         }
     }
     $targetDir = 'uploads';
     if (!is_dir($targetDir)) {
         $ret = mkdir($targetDir, 777, true);
         if (!$ret) {
             throw new \RuntimeException("Could not create target directory to move temporary file into.");
         }
     }
     $file->move($targetDir, basename($targetFilePath));
     return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
 }
開發者ID:kevin-ta,項目名稱:Form-wizard,代碼行數:25,代碼來源:UploadFileMover.php

示例13: preUpload

 public function preUpload()
 {
     if (null !== $this->file_domicile) {
         // do whatever you want to generate a unique name
         $this->path_domicile = uniqid() . '.' . $this->file_domicile->guessExtension();
     }
     if (null !== $this->file_prestations) {
         // do whatever you want to generate a unique name
         $this->path_prestations = uniqid() . '.' . $this->file_prestations->guessExtension();
     }
     if (null !== $this->file_salaire_1) {
         // do whatever you want to generate a unique name
         $this->path_salaire_1 = uniqid() . '.' . $this->file_salaire_1->guessExtension();
     }
     if (null !== $this->file_salaire_2) {
         // do whatever you want to generate a unique name
         $this->path_salaire_2 = uniqid() . '.' . $this->file_salaire_2->guessExtension();
     }
     if (null !== $this->file_salaire_3) {
         // do whatever you want to generate a unique name
         $this->path_salaire_3 = uniqid() . '.' . $this->file_salaire_3->guessExtension();
     }
     if (null !== $this->file_impots) {
         // do whatever you want to generate a unique name
         $this->path_impots = uniqid() . '.' . $this->file_impots->guessExtension();
     }
 }
開發者ID:WildCodeSchool,項目名稱:projet-gesty,代碼行數:27,代碼來源:User.php

示例14: preUpload

 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if ($this->file === null) {
         return;
     }
     $this->extension = $this->file->guessExtension();
     $this->alt = $this->file->getClientOriginalName();
 }
開發者ID:gorvelyfab,項目名稱:koopa-gbs-app,代碼行數:12,代碼來源:Image.php

示例15: preUpload

 public function preUpload()
 {
     if (null !== $this->file) {
         $filename = sha1(uniqid(mt_rand(), true));
         $this->path = $this->getUploadDir() . '/' . $filename . '.' . $this->file->guessExtension();
         return $this->path;
     }
 }
開發者ID:rdbn,項目名稱:shopsnmarkets,代碼行數:8,代碼來源:AdvertisingPlatform.php


注:本文中的Symfony\Component\HttpFoundation\File\UploadedFile::guessExtension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。