Non-standard image/pjpeg mimetype on IE
Here’s a lovely little Internet Explorer “feature” that may have web developers cursing, so I figured I would write a brief post about it in the hope that IE doesn’t waste an hour of your life like it did mine.
If you develop in PHP and need to add image upload functionality to a project, you will hopefully check the mimetype of each uploaded file to reduce the chance that it is a virus-laden script file or something equally nasty.
It’s quite easy to do by querying the “type” property of the uploaded file object. This page from the online PHP documentation has the details.
When checking an image upload, I normally check that the uploaded file’s mimetype is either image/jpeg, image/png or image/gif. These are standard mimetypes and everything works as it should, with users of the site uploading images to their hearts’ content.
Well, it works as it should until someone using Internet Explorer tries to upload a progressive JPEG image (a progressive JPEG is simply one that appears gradually more detailed when loaded, instead of loading from the top edge down). Every browser in the world treats such files as normal image/jpeg files, as they should. Except Internet Explorer of course, which uses the completely made-up mimetype of image/pjpeg.
Yes, that’s right, Microsoft invented their OWN mimetype for this solitary JPEG sub-type, presumably for no other reason than to annoy web developers the world over.
Add this to the list of mimetypes you check, and of course everything works fine. But you shouldn’t have to.
All I can say is, way to go Microsoft. Just when I thought you couldn’t surprise and disappoint me any more, you’ve succeeded in doing it again.