Skip to content

Commit

Permalink
allow absolute file path for Storage::putFile (#31040)
Browse files Browse the repository at this point in the history
  • Loading branch information
SjorsO authored and taylorotwell committed Jan 6, 2020
1 parent d5deffa commit f3c1f48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Illuminate/Filesystem/FilesystemAdapter.php
Expand Up @@ -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);
}

Expand Down
30 changes: 30 additions & 0 deletions tests/Filesystem/FilesystemAdapterTest.php
Expand Up @@ -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);
}
}

0 comments on commit f3c1f48

Please sign in to comment.