mat3000000 Posted June 25, 2011 Share Posted June 25, 2011 This code works in IE9, chrome safari etc, however does not work in IE7 or 8. How else could i do this? $imageData = @getimagesize($name); if($imageData === FALSE || !($imageData[2] == IMAGETYPE_JPEG)) $errors[] = 'Image must be a .jpg file.'; Quote Link to comment https://forums.phpfreaks.com/topic/240360-help-with-identifying-jpeg/ Share on other sites More sharing options...
cssfreakie Posted June 25, 2011 Share Posted June 25, 2011 check the extension. by exploding the file name. $string = "lala.mama.jaja.yaya.tata.moemoe.jpg"; $myarray = explode('.', $string); $extension = $myarray[count($myarray)-1]; // gets the last part echo $extension; // outputs jpg From there on you only need to check the value of $extension to what you expect, in this case a jpg. or do something like this: echo substr(basename($string), -3); // outputs jpg Quote Link to comment https://forums.phpfreaks.com/topic/240360-help-with-identifying-jpeg/#findComment-1234645 Share on other sites More sharing options...
MadTechie Posted June 25, 2011 Share Posted June 25, 2011 IE7 & 8, give progressive jpegs the type "image/pjpeg" instead of "image/jpeg" So try if($imageData === FALSE || !($imageData[2] == IMAGETYPE_JPEG || !($imageData[2] == 'image/pjpeg')) Quote Link to comment https://forums.phpfreaks.com/topic/240360-help-with-identifying-jpeg/#findComment-1234649 Share on other sites More sharing options...
PFMaBiSmAd Posted June 25, 2011 Share Posted June 25, 2011 The getimagesize returned index [2] is an integer (the IMAGETYPE_JPEG defined constant has the value 2.) Index [4] is the mime type. I would troubleshoot what value you are getting by using var_dump() on the returned value and given that you have an @ on the getimagesize statement to suppress errors, it is likely some other problem is occurring before that point. What php error, if any, do you get when you remove the @? Quote Link to comment https://forums.phpfreaks.com/topic/240360-help-with-identifying-jpeg/#findComment-1234671 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.