Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Allow absolute file path for Storage::putFile() #31040

Merged
merged 1 commit into from Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}