Laravel upload file with original file name.

When using laravel filesystem to upload files it automatically assigns a filename to the file. If you want to use the original filename or specify any other file name, you can do so by using storeAs method of the filesystem.

Here is how you can use the original filename


$file = $request->file('avatar');
$fileName = $file->getClientOriginalName()
$file->storeAs('avatars', $fileName);
//If you want to specify the disk, you can pass that as the third parameter.
$file->storeAs('avatars', $fileName, 's3');

Related Articles

Leave a reply:

Your email address will not be published.

Site Footer