Laravel Problem with UploadedFile getClientOriginalExtension() returns empty string

In Laravel when uploading files sometime getClientOriginalExtension() returns empty string.

Here is below explanation of  problem and solution for it.

The getClientOriginalExtension() method returns the original file extension.
It is extracted from the initial file name that was uploaded. Then it shouldn’t be thought-about as a safe value.
Input::file('File')->getClientOriginalExtension();

So we should use guessExtension() method for resolution.

The guessExtension() method returns the extension based on the mime type.

This methodology uses the mime type as guessed by getMimeType() to guess the file extension.

Input::file('File')->guessExtension();

We think above solution will work for everyone who have this problem. Certainly for this stuff as well, we have GitHub source code link ready to grab it easily. We hope you discover this blog helpful and you’ve got any queries or feedback be at liberty to feature comment below this content.

Don’t miss the next post!

Loading

Related Posts