php - finfo_file() returns wrong mime type for some images? -


I allow the image upload on my website and I need to get the file type to upload the file so that I can see Can I see what type is in the whitelist and is allowed to upload.

I'm using it using finfo_file () , but it does not work in all cases. Here's my code:

  // mime type get $ finfo = finfo_open (FILEINFO_MIME_TYPE); $ Mime = finfo_file ($ finfo, $ filePath); Echo $ mime;   

Try the above code on the above image and say that the mime type is application / octet-stream when it is Clearly a JPG file.

Why the financefolder () is not working with the test image? Whatever problem can I fix so that I can get the file type correctly?

Alternatively, you can use the exif_imagetype () with image_type_to_mime_type () can also be used. Example: function get_mime ($ url) {$ image_type = exif_imagetype ($ url); Return image_type_to_mime_type ($ image_type); } Echo get_mime ('http://ecx.images-amazon.com/images/I/41q8koaxM0L.jpg'); // image / jpeg

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -