You are here

public function UploadedFile::moveTo in Lockr 7.3

Parameters

string $targetPath Path to which to move the uploaded file.:

Throws

RuntimeException if the upload was not successful.

InvalidArgumentException if the $path specified is invalid.

RuntimeException on any error during the move operation, or on the second or subsequent call to the method.

Overrides UploadedFileInterface::moveTo

See also

http://php.net/is_uploaded_file

http://php.net/move_uploaded_file

File

vendor/guzzlehttp/psr7/src/UploadedFile.php, line 247

Class

UploadedFile

Namespace

GuzzleHttp\Psr7

Code

public function moveTo($targetPath) {
  $this
    ->validateActive();
  if (false === $this
    ->isStringNotEmpty($targetPath)) {
    throw new InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string');
  }
  if ($this->file) {
    $this->moved = php_sapi_name() == 'cli' ? rename($this->file, $targetPath) : move_uploaded_file($this->file, $targetPath);
  }
  else {
    copy_to_stream($this
      ->getStream(), new LazyOpenStream($targetPath, 'w'));
    $this->moved = true;
  }
  if (false === $this->moved) {
    throw new RuntimeException(sprintf('Uploaded file could not be moved to %s', $targetPath));
  }
}