当前位置: 首页>>代码示例>>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;未经允许,请勿转载。