/** * @param $targetPath * @return File * @throws PartialUploadException */ public function moveLocal($targetPath) { // source stream $sourceFile = $this->getFile(); $sourceFileReadStream = $sourceFile->getStream('r'); // target stream $targetFile = new File($targetPath, $sourceFile->getOriginalBasename(), $sourceFile->getSize(), $sourceFile->getType()); $targetFileWriteStream = $targetFile->getStream('w+'); // move stream content $size = stream_copy_to_stream($sourceFileReadStream, $targetFileWriteStream); // close resources fclose($sourceFileReadStream); fclose($targetFileWriteStream); // check copied file size if ($size !== $this->getFileSize()) { throw new PartialUploadException('Partial upload. Expected ' . $this->getFileSize() . ', found ' . $size); } return $targetFile; }