what is the diffrence between getClientOriginalExtension() and Extension() in Laravel?

Both methods returns the extention of the uploaded file, so why they both existe ?
Can’t find any diffrence between them.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

These methods are available on every IlluminateHttpUploadedFile.

getClientOriginalExtension() returns the extension extracted from the original file name. If you send image.png, it’ll be png

extension() returns the extension extracted from the file itself (using the mime type).

For instance, if you have a image.pdf file, you rename it image.png and then you upload it to your app:

  • getClientOriginalExtension() will return png
  • extension() will return pdf (or null if the mime type cannot be read)

Method 2

getClientOriginalExtension gets CLIENT extension, not the real mime-type extension, to get that use extension it is more secure

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x