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


PHP File::move方法代碼示例

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


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

示例1: upload

 /**
  * @throws FileException
  */
 public function upload()
 {
     if ($this->file instanceof File) {
         $name = sha1($this->file->getClientOriginalName() . uniqid() . getrandmax()) . '.' . $this->file->guessExtension();
         $this->file->move($this->getWeb() . $this->folder, $name);
         $this->file = $name;
     } else {
         throw new FileException('It must be a Symfony\\Component\\HttpFoundation\\File\\File instance');
     }
 }
開發者ID:radmar,項目名稱:RedactorBundle,代碼行數:13,代碼來源:Resource.php

示例2: upload

 public function upload()
 {
     if (null === $this->file) {
         return;
     }
     // if there is an error when moving the file, an exception will
     // be automatically thrown by move(). This will properly prevent
     // the entity from being persisted to the database on error
     $this->file->move($this->getUploadRootDir(), $this->charte_file);
     unset($this->file);
 }
開發者ID:luciemannechez,項目名稱:projet-intranet_hopital,代碼行數:11,代碼來源:Charte.php

示例3: move

 /**
  * @param FormEvent $event
  */
 public function move(FormEvent $event)
 {
     $data = $event->getData();
     if (is_callable($this->dstDir)) {
         $dstDir = call_user_func($this->dstDir, $event->getForm()->getParent()->getData());
     } else {
         $dstDir = $this->dstDir;
     }
     if (!empty($data)) {
         foreach ($data as $key => $path) {
             // First check if the file is still in tmp directory
             $originalFilename = $this->rootDir . '/../web/' . trim($path, '/');
             $destinationFilename = $this->rootDir . '/../web/' . trim($dstDir, '/') . '/' . basename($path);
             $webPath = rtrim($dstDir, '/') . '/' . basename($path);
             if (file_exists($originalFilename)) {
                 // if it does, then move it to the destination and update the data
                 $file = new File($originalFilename);
                 $file->move(dirname($destinationFilename));
                 // modify the form data with the new path
                 $data[$key] = $webPath;
             } else {
                 // otherwise check if it is already on the destination
                 if (file_exists($destinationFilename)) {
                     // if it does, simply modify the form data with the new path
                     // modify the form data with the new path
                     $data[$key] = $webPath;
                 } else {
                     // TODO :  check if we need to throw an exception here
                     unset($data[$key]);
                 }
             }
         }
         $event->setData($data);
     }
 }
開發者ID:leapt,項目名稱:admin-bundle,代碼行數:38,代碼來源:MultiUploadSubscriber.php

示例4: handle

 protected function handle()
 {
     $request = $this->getRequest();
     $posts = $request->request;
     $file_path = $posts->get('image_path');
     $x = $posts->get('x');
     $y = $posts->get('y');
     $w = $posts->get('w');
     $h = $posts->get('h');
     $path_info = pathinfo($file_path);
     $imagine = new Imagine();
     $raw_image = $imagine->open($file_path);
     $large_image = $raw_image->copy();
     $large_image->crop(new Point($x, $y), new Box($w, $h));
     $large_file_path = "{$path_info['dirname']}/{$path_info['filename']}_large.{$path_info['extension']}";
     $large_image->save($large_file_path, array('quality' => 70));
     $origin_dir_name = $path_info['dirname'];
     $new_directory = str_replace('/tmp', '', $origin_dir_name);
     $new_file = new File($large_file_path);
     $new_file->move($new_directory, "{$path_info['filename']}.{$path_info['extension']}");
     $container = $this->getContainer();
     $cdn_url = $container->getParameter('cdn_url');
     $new_uri = $cdn_url . '/upload/' . $path_info['filename'] . '.' . $path_info['extension'];
     @unlink($large_file_path);
     @unlink($file_path);
     return new JsonResponse(array('picture_uri' => $new_uri));
 }
開發者ID:aeshion,項目名稱:ZeroPHP,代碼行數:27,代碼來源:ActionIconCrop.php

示例5: moveFile

 /**
  * @param File $image
  * @param string $prefix
  * @param String $path
  * @return string
  */
 public function moveFile(File $image, $path, $prefix = '')
 {
     $extension = $image->guessExtension();
     $code = strtoupper($this->request->get('code'));
     $fileName = $code . '-' . $prefix . '.' . $extension;
     $image->move(public_path() . $path, $fileName);
     return $path . $fileName;
 }
開發者ID:SkysoulDesign,項目名稱:mirage.dev,代碼行數:14,代碼來源:CreateProductJob.php

示例6: move

 /**
  * {@inheritDoc}
  *
  * Use the move function provided by Symfony File Object
  */
 public function move(BaseFileInterface $baseFile)
 {
     $name = $this->getNamer()->rename($baseFile);
     $file = new File($this->getUri($baseFile));
     $baseFile->setPath(sprintf('%s/%s', $this->getUploadDir(), $name));
     $baseFile->setName($name);
     $file->move($this->getUploadDir(), $name);
 }
開發者ID:P3PO,項目名稱:VlabsMediaBundle,代碼行數:13,代碼來源:LocalFileSystemHandler.php

示例7: saveFile

 /**
  * Save uploaded file without validation
  *
  * @param File $file
  * @param string $newLocation
  * @param string $newName
  * @throws FileException
  * @return File
  */
 protected function saveFile(File $file, $newLocation, $newName = "")
 {
     $name = $file->getClientOriginalName();
     if ($newName) {
         $name = $newName;
     }
     return $file->move($this->createFolderIfNotExist($newLocation), $this->getUniqueFileName($name, $newLocation));
 }
開發者ID:LazyNewbie,項目名稱:boilerplate,代碼行數:17,代碼來源:FilesTrait.php

示例8: setAvatarFile

 /**
  * Set the avatar of the object to be a specific file
  *
  * @param  File|null $file The avatar file
  * @return self
  */
 public function setAvatarFile($file)
 {
     if ($file) {
         $filename = $this->getAvatarFileName();
         $file->move(DOC_ROOT . static::AVATAR_LOCATION, $filename);
         $this->setAvatar(static::AVATAR_LOCATION . $filename);
     }
     return $this;
 }
開發者ID:kleitz,項目名稱:bzion,代碼行數:15,代碼來源:AvatarModel.php

示例9: storeFileInPath

 public function storeFileInPath($path, File $file, $name = null)
 {
     $filename = $name ? $name : $file->getClientOriginalName();
     for ($i = 2; file_exists($path . $filename); $i++) {
         $filename = $i . '_' . $filename;
     }
     $file->move($path, $filename);
     return $filename;
 }
開發者ID:joadr,項目名稱:cms,代碼行數:9,代碼來源:FilesHelper.php

示例10: handle

 protected function handle()
 {
     $request = $this->getRequest();
     $posts = $request->request;
     $crop_type = $request->query->get('type');
     $file_path = $posts->get('image_path');
     $x = $posts->get('x');
     $y = $posts->get('y');
     $w = $posts->get('w');
     $h = $posts->get('h');
     $path_info = pathinfo($file_path);
     $imagine = new Imagine();
     $raw_image = $imagine->open($file_path);
     $large_image = $raw_image->copy();
     $large_image->crop(new Point($x, $y), new Box($w, $h));
     $large_file_path = "{$path_info['dirname']}/{$path_info['filename']}_large.{$path_info['extension']}";
     $large_image->save($large_file_path, array('quality' => 100));
     $origin_dir_name = $path_info['dirname'];
     $new_file = new File($large_file_path);
     // 重命名文件
     if ($crop_type == 'icon') {
         $format_dir = '/favicon/{yyyy}{mm}{dd}';
     } elseif ($crop_type == 'logo') {
         $format_dir = '/logo/{yyyy}{mm}{dd}';
     } else {
         $format_dir = '/image/{yyyy}{mm}{dd}';
     }
     $format_filename = '{time}{rand:6}';
     $t = time();
     $d = explode('-', date("Y-y-m-d-H-i-s"));
     $new_path = str_replace("{yyyy}", $d[0], $format_dir);
     $new_path = str_replace("{yy}", $d[1], $new_path);
     $new_path = str_replace("{mm}", $d[2], $new_path);
     $new_path = str_replace("{dd}", $d[3], $new_path);
     $new_path = str_replace("{hh}", $d[4], $new_path);
     $new_path = str_replace("{ii}", $d[5], $new_path);
     $new_path = str_replace("{ss}", $d[6], $new_path);
     $new_file_name = $format_filename;
     $new_file_name = str_replace("{time}", $t, $new_file_name);
     $new_file_name = preg_replace("/[\\|\\?\"\\<\\>\\/\\*\\\\]+/", '', $new_file_name);
     //替換隨機字符串
     $randNum = rand(1, 10000000000) . rand(1, 10000000000);
     if (preg_match("/\\{rand\\:([\\d]*)\\}/i", $new_file_name, $matches)) {
         $new_file_name = preg_replace("/\\{rand\\:[\\d]*\\}/i", substr($randNum, 0, $matches[1]), $new_file_name);
     }
     $new_file_name = $new_file_name . '.' . $path_info['extension'];
     $new_directory = str_replace('/tmp', '/upload' . $new_path, $origin_dir_name);
     $new_file->move($new_directory, $new_file_name);
     $container = $this->getContainer();
     $cdn_url = $container->getParameter('cdn_url');
     $new_uri = $cdn_url . '/upload' . $new_path . '/' . $new_file_name;
     @unlink($large_file_path);
     @unlink($file_path);
     return new JsonResponse(array('picture_uri' => $new_uri));
 }
開發者ID:aeshion,項目名稱:ZeroPHP,代碼行數:55,代碼來源:ActionCrop.php

示例11: setAvatarFile

 /**
  * Set the avatar of the object to be a specific file
  *
  * @param  File|null $file The avatar file
  * @return self
  */
 public function setAvatarFile($file)
 {
     if ($file) {
         // We don't use File's fread() because it's unavailable in less
         // recent PHP versions
         $path = $file->getPath() . '/' . $file->getFilename();
         $content = file_get_contents($path);
         $path = $this->getAvatarPath(null, false, false);
         $filename = $this->getAvatarFileName($content);
         $file->move(DOC_ROOT . $path, $filename);
         $this->setAvatar($path . $filename);
     }
     return $this;
 }
開發者ID:blast007,項目名稱:bzion,代碼行數:20,代碼來源:AvatarModel.php

示例12: testMove

 public function testMove()
 {
     $path = __DIR__ . '/Fixtures/test.copy.gif';
     $targetPath = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'test.target.gif';
     @unlink($path);
     @unlink($targetPath);
     copy(__DIR__ . '/Fixtures/test.gif', $path);
     $file = new File($path);
     $file->move($targetPath);
     $this->assertTrue(file_exists($targetPath));
     $this->assertFalse(file_exists($path));
     $this->assertEquals($targetPath, $file->getPath());
     @unlink($path);
     @unlink($targetPath);
 }
開發者ID:spf13,項目名稱:symfony,代碼行數:15,代碼來源:FileTest.php

示例13: store

 /**
  * @param \Exolnet\Image\Imageable                    $image
  * @param \Symfony\Component\HttpFoundation\File\File $file
  * @return bool
  * @throws \Exolnet\Core\Exceptions\ServiceValidationException
  */
 public function store(Imageable $image, File $file)
 {
     if (!$image->getFilename()) {
         throw new ServiceValidationException('Could not store image with an empty filename.');
     }
     $path = dirname($image->getImagePath());
     $filename = basename($image->getImagePath());
     if (!$this->filesystem->exists($path)) {
         $this->filesystem->makeDirectory($path, 0755, true);
     }
     if (!$this->filesystem->isWritable($path)) {
         throw new ServiceValidationException('The image base path "' . $path . '" is not writable.');
     }
     $file->move($path, $filename);
     return true;
 }
開發者ID:eXolnet,項目名稱:laravel-image,代碼行數:22,代碼來源:FilesystemRepository.php

示例14: move

 /**
  * Move the uploaded file from the temporary location to the permanent one
  * if required by configuration.
  *
  * @throws FileUploadException
  *
  * @return true
  */
 public function move()
 {
     $this->checkDirectories();
     $targetDir = $this->getTargetFileDirectory();
     $targetFile = $this->getTargetFileName();
     try {
         $this->file->move($targetDir, $targetFile);
         $this->fullPath = realpath($targetDir . DIRECTORY_SEPARATOR . $targetFile);
         $this->app['logger.system']->debug('[BoltForms] Moving uploaded file to ' . $this->fullPath . '.', array('event' => 'extensions'));
     } catch (FileException $e) {
         $error = 'File upload aborted as the target directory could not be writen to.';
         $this->app['logger.system']->error('[BoltForms] ' . $error . ' Check permissions on ' . $targetDir, array('event' => 'extensions'));
         throw new FileUploadException('File upload aborted as the target directory could not be writen to.');
     }
     return true;
 }
開發者ID:evertalbers,項目名稱:bolt-extension-boltforms,代碼行數:24,代碼來源:FileUpload.php

示例15: put

 /**
  * @param resource|string|UploadedFile $resource
  * @return string Asset identifier
  */
 public function put($resource)
 {
     $tmpFileName = tempnam('/tmp', 'test_');
     if ($resource instanceof UploadedFile) {
         $pathinfo = pathinfo($tmpFileName);
         $resource->move($pathinfo['dirname'], $pathinfo['basename']);
     } else {
         file_put_contents($tmpFileName, $resource);
     }
     $checksum = sha1_file($tmpFileName);
     $file = new File($tmpFileName);
     $targetFileName = $checksum . '.' . $file->guessExtension();
     $target = $file->move($this->storageDirectory, $targetFileName);
     $filesystem = new Filesystem();
     $filesystem->chmod($target, 0777);
     return $targetFileName;
 }
開發者ID:aptoma,項目名稱:silex-extras,代碼行數:21,代碼來源:FileStorage.php


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