本文整理汇总了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');
}
}
示例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);
}
示例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);
}
}
示例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));
}
示例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;
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}