Skip to content

Commit d9c07ae

Browse files
committed
Bug fixes
1 parent 94fbae1 commit d9c07ae

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/FileUploader.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ public function upload($path = '', $storage = 'public')
123123
*/
124124
public function uploadAs($filename, $path = '', $storage = 'public')
125125
{
126-
$filename = $filename
127-
? $filename . '.' . $this->file->getClientOriginalExtension()
128-
: $this->file->hashName();
126+
$filename = $filename ?: $this->file->hashName();
129127

130128
if ($this->image) {
131-
$imagePath = $path . $filename;
129+
$imagePath = "{$path}/{$filename}";
130+
131+
if (!Storage::disk($storage)->exists($path)) {
132+
Storage::disk($storage)->makeDirectory($path);
133+
}
132134

133135
$this->image->save(Storage::disk($storage)->path($imagePath));
134136

tests/FileUploaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public function testItUploadsFilesUnderSpecifiedNames()
3131

3232
$file = UploadedFile::fake()->create('file.pdf', 100);
3333

34-
$filename = 'document';
34+
$filename = 'document.pdf';
3535

3636
$path = FileUploader::make($file)->uploadAs($filename);
3737

38-
$this->assertEquals("{$filename}.pdf", $path);
38+
$this->assertEquals($filename, $path);
3939
Storage::disk('public')->assertExists($path);
4040
}
4141

@@ -84,12 +84,12 @@ public function testItReplacesTheOldFileWithTheNewFileUnderSpecifiedName()
8484

8585
$newFile = UploadedFile::fake()->create('new_file.pdf', 100);
8686

87-
$newFilename = 'new_document';
87+
$newFilename = 'new_document.pdf';
8888
$newPath = FileUploader::make($newFile)->replaceAs($oldPath, $newFilename);
8989

9090
Storage::disk('public')->assertMissing($oldPath);
9191

92-
$this->assertEquals("{$newFilename}.pdf", $newPath);
92+
$this->assertEquals($newFilename, $newPath);
9393
Storage::disk('public')->assertExists($newPath);
9494
}
9595

0 commit comments

Comments
 (0)