PHP Image Uploader - IE “pjpeg” MIME type, not wor

2019-09-09 03:21发布

问题:

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!

回答1:

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.