/** * {@inheritdoc} * * @see http://php.net/is_uploaded_file * @see http://php.net/move_uploaded_file * * @param string $targetPath Path to which to move the uploaded file. * * @throws RuntimeException if the upload was not successful. * @throws InvalidArgumentException if the $path specified is invalid. * @throws RuntimeException on any error during the move operation, or on * the second or subsequent call to the method. */ public function moveTo($targetPath) { $this->validateActive(); if ($this->isStringNotEmpty($targetPath) === false) { 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 { Util::copyToStream($this->getStream(), new LazyOpenStream($targetPath, 'w')); $this->moved = true; } if ($this->moved === false) { throw new RuntimeException(sprintf('Uploaded file could not be moved to %s', $targetPath)); } }
public function testStopsCopyToSteamWhenReadFailsWithMaxLen() { $body = 'foobaz'; $stream = fopen('php://temp', 'r+'); fwrite($stream, $body); fseek($stream, 0); $s1 = new Stream($stream); $s1 = FnStream::decorate($s1, ['read' => function () { return ''; }]); $s2 = new Stream(fopen('php://temp', 'r+')); Util::copyToStream($s1, $s2, 10); $this->assertEquals('', (string) $s2); }