You are here

public function UploadedFile::move in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/File/UploadedFile.php \Symfony\Component\HttpFoundation\File\UploadedFile::move()

Moves the file to a new location.

Parameters

string $directory The destination folder:

string $name The new file name:

Return value

File A File object representing the new file

Throws

FileException if, for any reason, the file could not have been moved

Overrides File::move

File

vendor/symfony/http-foundation/File/UploadedFile.php, line 216

Class

UploadedFile
A file uploaded through a form.

Namespace

Symfony\Component\HttpFoundation\File

Code

public function move($directory, $name = null) {
  if ($this
    ->isValid()) {
    if ($this->test) {
      return parent::move($directory, $name);
    }
    $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($this
    ->getErrorMessage());
}