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


PHP UploadedFile::isValid方法代码示例

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


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

示例1: execute

 public function execute()
 {
     if ($this->photo->isValid()) {
         $name = sha1($this->user->getId() . $this->user->getLogin() . $this->user->getRegisteredAt() . time() . uniqid('ffdf'));
         $photoUploader = new PhotoFormatter($this->photo->getRealPath(), self::MINIMUM_SIZE, self::MAXIMUM_SIZE, $this->output);
         $old = $this->user->getAvatar();
         $photoUploader->setNewName($name);
         $photoUploader->loadAndScale(self::START_SIZE);
         $this->user->setAvatar($name);
         $this->repository->update($this->user);
         if (!empty($old)) {
             $photoUploader->removeOld($old, self::START_SIZE);
         }
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:15,代码来源:UserProfilePhotoIntent.php

示例2: upload

 protected function upload(UploadedFile $file, $oldFile)
 {
     $list = "";
     //        foreach($files as $file)
     //        {
     //            $validator = Validator::make( array('file' => $file) , array('file' => array($this->Rule) ) );
     //
     //            if($validator->fails())
     //            {
     //laravel內建的驗證無法使用(可能是bug吧),所以自己寫一個
     foreach ($this->Rule as $rule) {
         if ($file->getClientOriginalExtension() == $rule) {
             if ($file->isValid()) {
                 if ($this->groupno != "") {
                     $year = substr($this->groupno, 1, 3);
                     $destinationPath = public_path() . '/upload/' . $year . '/' . $this->groupno;
                 } else {
                     $destinationPath = public_path() . '/upload/teacher';
                 }
                 $fileName = $file->getClientOriginalName();
                 File::delete($destinationPath . '/' . $oldFile);
                 $file->move($destinationPath, $fileName);
                 //用 "|" 隔開檔名
                 $list .= $fileName . "|";
             }
         }
     }
     //            }
     //        }
     $list = substr($list, 0, -1);
     return $list;
 }
开发者ID:BlackKite0206233,项目名称:Daan-Info-Web,代码行数:32,代码来源:Upload.php

示例3: handleUpload

 /**
  * @param UploadedFile|null $uploadedFile
  * @param array $options
  * @return AssetFile
  */
 public function handleUpload(UploadedFile $uploadedFile = null, array $options = [])
 {
     $resolver = new OptionsResolver();
     $resolver->setDefaults(['type' => null, 'fallbackType' => null, 'targetUri' => null])->setAllowedTypes(['type' => ['string', 'null'], 'fallbackType' => ['int', 'null'], 'targetUri' => ['string', 'null']])->setAllowedValues(['type' => ['image', 'audio', 'file', null]]);
     $options = $resolver->resolve($options);
     if (!$uploadedFile instanceof UploadedFile || !$uploadedFile->isValid() || !($assetFile = new AssetFile($uploadedFile, null, $options['fallbackType'])) || $assetFile->getType() === null) {
         throw new \RuntimeException('Invalid uploaded file');
     }
     $assetFile->setOriginalName($uploadedFile->getClientOriginalName());
     if ($options['type'] !== null) {
         $this->validateAssetFileType($assetFile, $options['type']);
     }
     if ($options['targetUri'] !== null) {
         $uploadsDir = $this->assetsResolver->uriToPath($options['targetUri']);
     } else {
         $uploadsDir = $this->assetsResolver->assetPath($assetFile->getType());
     }
     $tempFile = $uploadedFile->move($uploadsDir, $this->getTargetFileName($uploadedFile->getClientOriginalName(), $uploadsDir));
     $assetFile->setFile($tempFile);
     $uri = $this->assetsResolver->pathToUri($assetFile->getFile()->getPathname());
     if ($uri === null) {
         throw new \RuntimeException('Unable to retrieve uploaded file uri');
     }
     $assetFile->setUri($uri);
     return $assetFile;
 }
开发者ID:harentius,项目名称:blog-bundle,代码行数:31,代码来源:Manager.php

示例4: isFileUpload

 /**
  * @param string|array|UploadedFile $data
  *
  * @return bool
  */
 protected function isFileUpload($data)
 {
     if ($data instanceof UploadedFile) {
         return $data->isValid() && $data->getClientSize() > 0;
     }
     return is_array($data) && !empty($data['tmp_name']) && !empty($data['size']) && $data['error'] === UPLOAD_ERR_OK;
 }
开发者ID:acp3,项目名称:core,代码行数:12,代码来源:FileUploadValidationRule.php

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

示例6: putUploadedFile

 /**
  * Put and save a file in the public directory
  *
  * @param string path of the file
  * @return mixed keypath of file or false if error occurred during uploading
  */
 public static function putUploadedFile(UploadedFile $file)
 {
     if ($file->isValid()) {
         //Remove all the slashes that doesn't serve
         FileStorage::clearPublicStartPath();
         //Retrive and save the file extension of the file uploaded
         $fileExtension = $file->getClientOriginalExtension();
         //Save the public path with the start path
         $absolutePath = public_path() . '/' . FileStorage::$publicStartPath;
         //Generate a random name to use for the file uploaded
         $keyFile = FileStorage::generateKey(FileStorage::$keyLength) . '.' . $fileExtension;
         //Check if the file with the $keyFile name doesn't exist, else, regenerate it
         while (file_exists($absolutePath . '/' . ord($keyFile[0]) . '/' . $keyFile)) {
             $keyFile = FileStorage::generateKey(FileStorage::$keyLength) . '.' . $fileExtension;
         }
         //Move the uploaded file and save
         $file->move($absolutePath . '/' . ord($keyFile[0]), $keyFile);
         //Save the keypath (start path, sub path, file name)
         $keyPath = FileStorage::$publicStartPath . '/' . ord($keyFile[0]) . '/' . $keyFile;
         //Return public path of the file
         return $keyPath;
     } else {
         return false;
     }
 }
开发者ID:arooth,项目名称:FileStorage,代码行数:31,代码来源:FileStorage.php

示例7: upload

 public function upload(UploadedFile $file)
 {
     if ($file->isValid()) {
         $name = $file->getClientOriginalName();
         $size = $file->getClientSize();
     }
 }
开发者ID:vi-kon,项目名称:laravel-file-manager,代码行数:7,代码来源:FileManager.php

示例8: doRequestUpload

 /**
  * Upload file from the request
  *
  * @param  UploadedFile $file
  * @return Array $data Retrieve into the content of response
  * @throws BadRequestHttpException The file is too big
  */
 private function doRequestUpload(UploadedFile $file)
 {
     $tmpDirectory = $this->getApplication()->getTemporaryDir();
     $data = [];
     if (null !== $file) {
         if ($file->isValid()) {
             if ($file->getClientSize() <= $file->getMaxFilesize()) {
                 $data = $this->buildData($file->getClientOriginalName(), $file->guessExtension());
                 $file->move($tmpDirectory, $data['filename']);
                 $data['size'] = round($file->getClientSize() / 1024, 2);
                 if ($imageInfo = @getimagesize($data['path'])) {
                     if (isset($imageInfo[0]) && isset($imageInfo[1])) {
                         $data['width'] = $imageInfo[0];
                         $data['height'] = $imageInfo[1];
                     }
                 } else {
                     $data['width'] = 0;
                     $data['height'] = 0;
                 }
             } else {
                 throw new BadRequestHttpException('Too big file, the max file size is ' . $file->getMaxFilesize());
             }
         } else {
             throw new BadRequestHttpException($file->getErrorMessage());
         }
     }
     return $data;
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:35,代码来源:ResourceController.php

示例9: saveUploadedFile

 /**
  * @param string $containerName
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param string|null $relativePath
  *
  * @return bool
  */
 public function saveUploadedFile($containerName, UploadedFile $file, $relativePath)
 {
     if ($file->isValid() === false) {
         return false;
     }
     $fileName = $file->getClientOriginalName();
     $filePath = $this->getFullFileName($containerName, $fileName);
     return $this->move($file->getRealPath(), $filePath);
 }
开发者ID:project-a,项目名称:spryker-file-upload,代码行数:16,代码来源:Storage.php

示例10: init

 /**
  * @param UploadedFile $file
  *
  * @return Uploader
  *
  * @throws UploaderException
  */
 public function init(UploadedFile $file)
 {
     // check if file correct
     if (!$file->isValid()) {
         throw new UploaderException($file->getErrorMessage());
     }
     $this->file = $file;
     return $this;
 }
开发者ID:NewwayLibs,项目名称:uploader,代码行数:16,代码来源:Uploader.php

示例11: uploadFile

 public function uploadFile(UploadedFile $file, $fileName, $path)
 {
     try {
         if ($file->isValid()) {
             $file->move($path, $fileName);
         }
     } catch (\Exception $ex) {
         throw $ex;
     }
 }
开发者ID:breenyoung,项目名称:wfadmin,代码行数:10,代码来源:UploadHandler.php

示例12: saveUploadedFile

 /**
  * Enregistre un fichier téléchargé en le déplaçant dans le répertoire $upload_directory sous le nom $filename.
  * On conserve l'extension du fichier d'origine
  *
  * @param UploadedFile $file
  * @param $uploadDirectory
  * @param $filename
  * @return bool
  */
 public function saveUploadedFile(UploadedFile $file, $uploadDirectory, $filename)
 {
     if (!$file->isValid()) {
         return false;
     }
     $this->upload_directory = $uploadDirectory;
     $this->filename = $filename . '.' . $file->getClientOriginalExtension();
     $file->move($this->upload_directory, $this->filename);
     return true;
 }
开发者ID:ChristopheBrun,项目名称:hLib,代码行数:19,代码来源:FileUploader.php

示例13: __construct

 /**
  * Constructor.
  *
  * @param Application $app
  * @param string      $formName
  * @param File        $file
  */
 public function __construct(Application $app, $formName, UploadedFile $file)
 {
     $this->app = $app;
     $this->formName = $formName;
     $this->file = $file;
     $this->fullPath = (string) $file;
     $this->fileName = basename($this->fullPath);
     $this->valid = $file->isValid();
     $this->config = $app[Extension::CONTAINER]->config;
 }
开发者ID:EfficiencyNetwork,项目名称:BoltForms,代码行数:17,代码来源:FileUpload.php

示例14: upload

 /**
  * Uploads the file
  *
  * @param UploadedFile $file
  * @param              $dir
  *
  * @return \WellCommerce\AppBundle\Entity\MediaInterface
  * @throws \Exception
  */
 public function upload(UploadedFile $file, $dir)
 {
     $uploadPath = $this->getUploadRootDir($dir);
     if (!$file->isValid()) {
         throw new \Exception('Passed file object is not valid');
     }
     $media = $this->createMediaFromUploadedFile($file);
     $this->saveResource($media);
     $file->move($uploadPath, $media->getPath());
     return $media;
 }
开发者ID:pguso,项目名称:WellCommerce,代码行数:20,代码来源:MediaManager.php

示例15: __construct

 /**
  * Constructor.
  *
  * @param Application $app
  * @param string      $formName
  * @param File        $file
  */
 public function __construct(Application $app, $formName, UploadedFile $file)
 {
     $this->app = $app;
     $this->formName = $formName;
     $this->file = $file;
     $this->fullPath = (string) $file;
     $this->fileName = basename($this->fullPath);
     $this->valid = $file->isValid();
     $extension = $app['extensions']->get('Bolt/BoltForms');
     $this->config = $extension->getConfig();
 }
开发者ID:pkdevboxy,项目名称:boltforms,代码行数:18,代码来源:FileUpload.php


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