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


PHP UploadedFile::move方法代碼示例

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


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

示例1: handleUploadedFile

 /**
  * Handles an uploaded file by putting it in the $targetDir.
  * 
  * @param UploadedFile $uploadedFile File object that has been uploaded - usually taken from Request object.
  * @param string $targetDir [optional] Where to (relatively to the storage root dir) put the file?
  * @param array $allowed [optional] What files are allowed? If not matching then will throw exception.
  * @param int $maxFileSize [optional] What is the maximum allowed file size for this file?
  * @return File
  */
 public function handleUploadedFile(UploadedFile $uploadedFile, $targetDir = '/', array $allowed = array(), $maxFileSize = 0)
 {
     array_walk($allowed, function ($ext) {
         return strtolower($ext);
     });
     $targetDir = trim($targetDir, '/');
     $targetDir = $this->path . $targetDir . (empty($targetDir) ? '' : '/');
     $filenameElements = explode('.', $uploadedFile->getClientOriginalName());
     $extension = array_pop($filenameElements);
     $extension = strtolower($extension);
     $filename = implode('.', $filenameElements);
     $targetName = StringUtils::fileNameFriendly($filename . '-' . StringUtils::random() . '.' . $extension);
     $targetPath = $targetDir . $targetName;
     // create unique file name
     while (file_exists($targetPath)) {
         $targetName = StringUtils::fileNameFriendly($filename . '-' . StringUtils::random() . '.' . $extension);
         $targetPath = $targetDir . $targetName;
     }
     // basic check for allowed type
     if (!empty($allowed) && !in_array($extension, $allowed)) {
         throw new FileException('The uploaded file is not of a valid type (allowed: ' . implode(', ', $allowed) . ').');
     }
     // basic check for max allowed size
     if ($maxFileSize && $uploadedFile->getSize() > $maxFileSize) {
         throw new FileException('The uploaded file is too big (max allowed size is ' . StringUtils::bytesToString($maxFileSize) . ').');
     }
     try {
         $movedFile = $uploadedFile->move(rtrim($targetDir, '/'), $targetName);
     } catch (SfFileException $e) {
         // if exception thrown then convert it to our exception
         throw new FileException($e->getMessage(), $e->getCode());
     }
     $file = $this->convertSfFileToStorageFile($movedFile);
     return $file;
 }
開發者ID:splot,項目名稱:framework-extra-module,代碼行數:44,代碼來源:SimpleStorage.php

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

示例3: save

 /**
  * {@inheritdoc}
  */
 public function save()
 {
     if (null !== $this->file) {
         $this->file->move($this->getUploadRootDir(), $this->path);
         unset($this->file);
     }
     return $this;
 }
開發者ID:MdxlMonta,項目名稱:Tuto1,代碼行數:11,代碼來源:Upload.php

示例4: upload

 public function upload()
 {
     if (null === $this->file) {
         return;
     }
     $name = $this->file->getClientOriginalName();
     $this->file->move($this->getUploadRootDir(), $name);
     $this->url = $name;
 }
開發者ID:bamper,項目名稱:webstore,代碼行數:9,代碼來源:UploadFile.php

示例5: save

 /**
  * Process the form.
  *
  * @return void
  */
 public function save()
 {
     // attach the photo to the flyer
     $photo = $this->flyer->addPhoto($this->makePhoto());
     // move the photo to the image folder
     $this->file->move($photo->baseDir(), $photo->name);
     // generate a thumbnail
     $this->thumbnail->make($photo->path, $photo->thumbnail_path);
 }
開發者ID:najibu,項目名稱:project-flyer,代碼行數:14,代碼來源:AddPhotoToFlyer.php

示例6: uploadAvatar

 /**
  * Uplaod a photo if exits.
  */
 protected function uploadAvatar()
 {
     if (!$this->file) {
         return;
     }
     $name = $this->makeFileName();
     $this->user['avatar'] = '/' . $this->baseDir . $name;
     $this->file->move($this->baseDir, $name);
     $this->fitAvatar($this->user['avatar']);
 }
開發者ID:socieboy,項目名稱:jupiter,代碼行數:13,代碼來源:UploadAvatarTrait.php

示例7: upload

 public function upload()
 {
     if ($this->rules->passes()) {
         try {
             $this->file->move($this->path . $this->subfolder, $this->filename . '.' . $this->file->getClientOriginalExtension());
             return true;
         } catch (\Exception $e) {
             dd($e->getMessage());
             return false;
         }
     }
     return false;
 }
開發者ID:orsic,項目名稱:bushido,代碼行數:13,代碼來源:FileUploader.php

示例8: handle

 /**
  * @param Filesystem $files
  * @param AccountManager $manager
  * @return mixed
  */
 public function handle(Filesystem $files, AccountManager $manager)
 {
     $temp_dir = storage_path('media') . '/' . $this->owner->getMediaFolder('images');
     $name = $this->uniqueName();
     $this->image->move($temp_dir, $name);
     $temp_file = $temp_dir . $name;
     $name_with_extension = $name . $this->extension($temp_file);
     $final_path = $temp_file . $name_with_extension;
     $files->move($temp_file, $final_path);
     $image = $this->dispatch(new StoreNewImage($manager->account(), $this->owner, $final_path));
     $files->delete($final_path);
     return $image;
 }
開發者ID:jaffle-be,項目名稱:framework,代碼行數:18,代碼來源:UploadNewImage.php

示例9: upload

 /**
  * @ORM\PostPersist()
  * @ORM\PostUpdate()
  */
 public function upload()
 {
     if (null === $this->file) {
         return;
     }
     if (null !== $this->tempFilename) {
         $oldFile = $this->getUploadRootDir() . '/' . $this->id . '.' . $this->tempFilename;
         if (file_exists($oldFile)) {
             unlink($oldFile);
         }
     }
     $this->file->move($this->getUploadRootDir(), $this->id . '.' . $this->getUrl());
 }
開發者ID:AlexandreRozier,項目名稱:Symfony,代碼行數:17,代碼來源:Image.php

示例10: save

 /**
  * Save the file to the fileable type and id
  */
 public function save()
 {
     $file = $this->makeFileRecord();
     // move the file and add the size to the file model
     $this->file->move($file->getSystemPath(), $file->filename);
     if (\File::exists($file->getSystemPath() . $file->filename)) {
         $file->filesize = \File::size($file->getSystemPath() . $file->filename);
     }
     if ($this->thumbnail->isPhoto($file->getSystemPath() . $file->filename)) {
         $this->thumbnail->make($file);
     }
     $file->save();
 }
開發者ID:grlf,項目名稱:laravel-portal-template,代碼行數:16,代碼來源:StoreFileableFiles.php

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

示例12: moveUploadedFile

 public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath, $fileName)
 {
     $originalName = $file->getFilename();
     // use filemtime() to have a more determenistic way to determine the subpath, otherwise its hard to test.
     // $relativePath = date('Y-m', filemtime($file->getPath()));
     $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 = $uploadBasePath . DIRECTORY_SEPARATOR . $relativePath;
     if (!is_dir($targetDir)) {
         $ret = mkdir($targetDir, umask(), true);
         if (!$ret) {
             throw new \RuntimeException("Could not create target directory to move temporary file into.");
         }
     }
     //$file->move($targetDir, basename($targetFilePath));
     //$file->move($targetDir, basename($fileName.'.'.$ext));
     $file->move($targetDir, basename($fileName));
     return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
 }
開發者ID:alangalipaud,項目名稱:ProjetQCM,代碼行數:29,代碼來源:UploadFileMover.php

示例13: upload

 public function upload(UploadedFile $file, $folder)
 {
     $path = $this->path . $folder . '/';
     $name = md5(uniqid(rand(), 1)) . '.' . $file->getClientOriginalExtension();
     $file->move($path, $name);
     return url('img', [$folder, $name]);
 }
開發者ID:za-laravel,項目名稱:laravel-gallery,代碼行數:7,代碼來源:ImageUploadService.php

示例14: __construct

 /**
  * Constructor
  *
  * @param UploadedFileBase $uploadedFile
  * @param CKFinder         $app
  *
  * @throws \Exception if file upload failed
  */
 public function __construct(UploadedFileBase $uploadedFile, CKFinder $app)
 {
     parent::__construct($uploadedFile->getClientOriginalName(), $app);
     $this->uploadedFile = $uploadedFile;
     $this->workingFolder = $app['working_folder'];
     $this->tempFilePath = tempnam($this->config->get('tempDirectory'), 'ckf');
     $pathinfo = pathinfo($this->tempFilePath);
     if (!is_writable($this->tempFilePath)) {
         throw new InvalidUploadException('The temporary folder is not writable for CKFinder');
     }
     try {
         $uploadedFile->move($pathinfo['dirname'], $pathinfo['basename']);
     } catch (\Exception $e) {
         $errorMessage = $uploadedFile->getErrorMessage();
         switch ($uploadedFile->getError()) {
             case UPLOAD_ERR_INI_SIZE:
             case UPLOAD_ERR_FORM_SIZE:
                 throw new InvalidUploadException($errorMessage, Error::UPLOADED_TOO_BIG, array(), $e);
             case UPLOAD_ERR_PARTIAL:
             case UPLOAD_ERR_NO_FILE:
                 throw new InvalidUploadException($errorMessage, Error::UPLOADED_CORRUPT, array(), $e);
             case UPLOAD_ERR_NO_TMP_DIR:
                 throw new InvalidUploadException($errorMessage, Error::UPLOADED_NO_TMP_DIR, array(), $e);
             case UPLOAD_ERR_CANT_WRITE:
             case UPLOAD_ERR_EXTENSION:
                 throw new AccessDeniedException($errorMessage, array(), $e);
         }
     }
 }
開發者ID:vobinh,項目名稱:PHP,代碼行數:37,代碼來源:UploadedFile.php

示例15: saveUserUploadedPhoto

 public function saveUserUploadedPhoto(UploadedFile $file)
 {
     $extension = CommonFunction::getFileExtension($file->getClientOriginalName());
     $fileName = md5(microtime(true)) . '.' . $extension;
     $file->move($this->getUserPhotoDir(), $fileName);
     return $fileName;
 }
開發者ID:tesmen,項目名稱:velo.local,代碼行數:7,代碼來源:FileWorker.php


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