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