diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index 249cefe6f7a5..8057b219c8ae 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -228,12 +228,14 @@ public function put($path, $contents, $options = []) * Store the uploaded file on the disk. * * @param string $path - * @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile $file + * @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $file * @param array $options * @return string|false */ public function putFile($path, $file, $options = []) { + $file = is_string($file) ? new File($file) : $file; + return $this->putFileAs($path, $file, $file->hashName(), $options); } diff --git a/tests/Filesystem/FilesystemAdapterTest.php b/tests/Filesystem/FilesystemAdapterTest.php index 5638aa4f0624..3ba9928bac14 100644 --- a/tests/Filesystem/FilesystemAdapterTest.php +++ b/tests/Filesystem/FilesystemAdapterTest.php @@ -271,4 +271,34 @@ public function testPutFileAsWithAbsoluteFilePath() $this->assertSame('normal file content', $filesystemAdapter->read($storagePath)); } + + public function testPutFile() + { + file_put_contents($filePath = $this->tempDir.'/foo.txt', 'uploaded file content'); + + $filesystemAdapter = new FilesystemAdapter($this->filesystem); + + $uploadedFile = new UploadedFile($filePath, 'org.txt', null, null, true); + + $storagePath = $filesystemAdapter->putFile('/', $uploadedFile); + + $this->assertSame(44, strlen($storagePath)); // random 40 characters + ".txt" + + $this->assertFileExists($filePath); + + $filesystemAdapter->assertExists($storagePath); + } + + public function testPutFileWithAbsoluteFilePath() + { + file_put_contents($filePath = $this->tempDir.'/foo.txt', 'uploaded file content'); + + $filesystemAdapter = new FilesystemAdapter($this->filesystem); + + $storagePath = $filesystemAdapter->putFile('/', $filePath); + + $this->assertSame(44, strlen($storagePath)); // random 40 characters + ".txt" + + $filesystemAdapter->assertExists($storagePath); + } }