I was finding the same issue but for a .docx file. I noticed that the $request->file('filename')->extension() method was incorrectly defining the filetype.
It actually says this in the docs
File Paths & Extensions
...This extension may be different from the extension that was supplied by the client
I had the same problem. This is my solution using methods more similar to those of @ahmadbadpey:
$file = new File($request->file);
// Generate unique name with real extension using the same method used by Storage::putFile()
$fileHash = str_replace('.' . $file->extension(), '', $file->hashName());
$fileName = $fileHash . '.' . $request->file('file')->getClientOriginalExtension();
$source = Storage::putFileAs('chat/attachments', $file, $fileName);
you can use the storeAs(PATH, NAME_YOU_WANT) method.
you can add time() method before the name to make it unique.
in the name parameter just use the $request->file('file_name')->getClientOriginalName() it will give the name with the extension
I wanted to upload a file type that is not in the usual list ('mp3', 'jpg' etc...) and getClientOriginalName() would return a .bin extension which in this case is obviously wrong.
My take on fixing this was using a PHP library function which reads the string name and finds everything after the "."
So in short to grab the extension you can do the following: