even PHP has 'bugs' with IE

Posted by silversky on Stack Overflow See other posts from Stack Overflow or by silversky
Published on 2010-03-18T23:07:39Z Indexed on 2010/03/18 23:11 UTC
Read the original article Hit count: 389

It's not a real bug BUT for sure it is not what you would expect. I have this sample code to upload images:

<?php
if($type=="image/jpg" || $type=="image/jpeg" || $type=="image/pjpeg" || $type=="image/tiff" || $type=="image/gif" || $type=="image/png") {
   // make upload
else echo "Incorect format ...."; 
?>

The problem is that that if I modify the extention of an image, let's say to .jpgq or even .jpg% and i try to upload it FF and Chrome will say that the file"s type is "application/octet-stream" and normaly the condition will be false

BUT since IE is 'smarter' that other brow. it will say that the file is "image/pjeg and the condition will be true and the file will be uploaded and of course latter any brow. will not be able to read / view the image.

It is not a bug because on msdn.microsoft.com it says that: "If the "suggested" (server-provided) MIME type is unknown (not known and not ambiguous), FindMimeFromData immediately returns this MIME type" and "If the server-provided MIME type is either known or ambiguous, the buffer is scanned in an attempt to verify or obtain a MIME type from the actual content." plus others 'inovative solutions from Microsoft'.

SO my questions are:

  1. Why is IE so 'smart' and when I upload the file to server it knows the real MIME type BUT it will fail to read it from the server ?
  2. How can i work around this issue (if the file doesn't have the right extention the condition has to be false)? Is it wise to check the extention format (and not the MIME type)?
  3. is any of the above extention not recomended to use ? Should I add others?

© Stack Overflow or respective owner

Related posts about php

Related posts about internet-explorer