Reputation: 922
How can I check if the file uploaded on my server is really an image? Not just a file with (jpg,png,gif) extension just to make it as "an image" file. I created an image compression service using imagemin, but I'm afraid if the uploaded file is really an image.
Upvotes: 19
Views: 27662
Reputation: 338
Another option is https://github.com/sindresorhus/image-type. Looks like mmmagic relies on libmagic which is a C lib and might be a lot to pull in...
Upvotes: 3
Reputation: 27221
Mime types are not useful. Try magic numbers or purely try to open the file. Read with link for more details. https://stackoverflow.com/a/8475542/1979882
http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html#Image
Upvotes: 1
Reputation: 1208
I have used the mmmagic module for this, it discovers mime types: mmmagic on Github
Upvotes: 8