fix
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait StoresUploads
|
||||
{
|
||||
/**
|
||||
* Store an uploaded file under a random name while preserving its real
|
||||
* extension (from the original filename). Laravel's default store() derives
|
||||
* the extension from the sniffed MIME type, which yields ".bin" for files
|
||||
* that sniff as application/octet-stream (e.g. some valid .mp3 files).
|
||||
*/
|
||||
protected function storeUpload(UploadedFile $file, string $folder, string $disk = 'public'): string
|
||||
{
|
||||
$ext = $file->getClientOriginalExtension()
|
||||
?: ($file->guessExtension() ?: 'bin');
|
||||
|
||||
return $file->storeAs($folder, Str::random(40) . '.' . $ext, $disk);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user