Drew
Drew

Reputation: 6872

PHP Image Uploader - IE "pjpeg" MIME type, not working

I am having a hard time with my image upload script, getting the images to upload in Internet Explorer. I have been searching Google for a solution and adding the "image/pjpeg" mime type seemed to work for everyone, but I have added it to my code and still cannot get it to work.

Here is what I have:

$acceptedExts = array ('jpg','jpeg');

if (  in_array($ext,$acceptedExts)
  &&  (  $_FILES["uploaded_file"]["type"] == "image/pjpeg"
      || $_FILES["uploaded_file"]["type"] == "image/jpeg")
  &&  ($_FILES["uploaded_file"]["size"] < 16000000)) {

Am I doing anything wrong?

Thanks!

Upvotes: 0

Views: 785

Answers (1)

Marc B
Marc B

Reputation: 360762

Try a var_dump($_FILES['uploaded_file']) to see exactly what IE's sending. It may be image/jpg or something completely different. However, it's bad form to use the user-provided ['type'] field for validation. It's trivial to forge that value. Better use a server-side method to figure out file type, such as get_image_size() or the FileInfo library, both of which return the true mime-type of the file.

Upvotes: 1

Related Questions