Error uploading .jpg with Internet Explorer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slpshtmike
Forum Newbie
Posts: 4
Joined: Sun Apr 09, 2006 11:09 am

Error uploading .jpg with Internet Explorer

Post by slpshtmike »

I have an image uploading script, and to ensure that the file being uploaded is an image I have the following if statement:

if (($_FILES['imagefile']['type'] == "image/gif") OR ($_FILES['imagefile']['type'] == "image/jpg") OR ($_FILES['imagefile']['type'] == "image/jpeg") OR ($_FILES['imagefile']['type'] == "image/bmp") OR ($_FILES['imagefile']['type'] == "image/GIF") OR ($_FILES['imagefile']['type'] == "image/JPG") OR ($_FILES['imagefile']['type'] == "image/JPEG") OR ($_FILES['imagefile']['type'] == "image/BMP")){


(some code here)

}else echo("error: invalid filetype");

The script works fine when I try to upload images in Firefox, but when using IE I recieve the "error: invalid filetype" when I try to upload .jpg images.

Has anyone ever encountered this before? Or have any idea why this is happening?

Your help is much appreciated,
Mike
slpshtmike
Forum Newbie
Posts: 4
Joined: Sun Apr 09, 2006 11:09 am

Post by slpshtmike »

I found the problem, ill post it here just incase anyone else runs into this.

While firefox reads the mime-type of a jpeg image as "image/jpeg", internet explorer reads it as "image/pjpeg"
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

I always wondered where this "image/pjpeg" mime type originated for IE ? Anyone have a clue ?

I am guessing its just another non-standard way for Microsoft to do things.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

relying on the browser to tell you what type of file the upload is (which is what you are doing here) is fairly dangerous as it is really easy to spoof any type I wished then. If you're looking for images, use getimagesize() instead. It will actually interrogate the binary data to see what kind of image, if any, the file is.
Post Reply