merged branch fabpot/move-uploaded-file-2_0 (PR #6221)
This PR was merged into the 2.0 branch.
Commits
-------
447ff91
[HttpFoundation] changed UploadedFile::move() to use move_uploaded_file() when possible (closes #5878, closes #6185)
Discussion
----------
[HttpFoundation] changed UploadedFile::move() to use move_uploaded_file() when possible (closes #5878, closes #6185)
An alternative for #5878 and it fixes #6185.
This commit is contained in:
commit
a12c685e3c
@ -523,6 +523,20 @@ class File extends \SplFileInfo
|
||||
* @api
|
||||
*/
|
||||
public function move($directory, $name = null)
|
||||
{
|
||||
$target = $this->getTargetFile($directory, $name);
|
||||
|
||||
if (!@rename($this->getPathname(), $target)) {
|
||||
$error = error_get_last();
|
||||
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
|
||||
}
|
||||
|
||||
@chmod($target, 0666 & ~umask());
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
protected function getTargetFile($directory, $name = null)
|
||||
{
|
||||
if (!is_dir($directory)) {
|
||||
if (false === @mkdir($directory, 0777, true)) {
|
||||
@ -534,14 +548,7 @@ class File extends \SplFileInfo
|
||||
|
||||
$target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));
|
||||
|
||||
if (!@rename($this->getPathname(), $target)) {
|
||||
$error = error_get_last();
|
||||
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
|
||||
}
|
||||
|
||||
chmod($target, 0666);
|
||||
|
||||
return new File($target);
|
||||
return new File($target, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,8 +189,21 @@ class UploadedFile extends File
|
||||
*/
|
||||
public function move($directory, $name = null)
|
||||
{
|
||||
if ($this->isValid() && ($this->test || is_uploaded_file($this->getPathname()))) {
|
||||
return parent::move($directory, $name);
|
||||
if ($this->isValid()) {
|
||||
if ($this->test) {
|
||||
return parent::move($directory, $name);
|
||||
} elseif (is_uploaded_file($this->getPathname())) {
|
||||
$target = $this->getTargetFile($directory, $name);
|
||||
|
||||
if (!@move_uploaded_file($this->getPathname(), $target)) {
|
||||
$error = error_get_last();
|
||||
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
|
||||
}
|
||||
|
||||
@chmod($target, 0666 & ~umask());
|
||||
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
|
||||
throw new FileException(sprintf('The file "%s" has not been uploaded via Http', $this->getPathname()));
|
||||
|
Reference in New Issue
Block a user