This commit is contained in:
2026-06-03 12:11:28 +03:30
parent bae1a2acb0
commit 0cb4954579
6 changed files with 51 additions and 15 deletions
+23
View File
@@ -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);
}
}