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