hi there, can anyone please help me with this problem!!! my picture upload code works fine in firefox but doesn't seem to work in IE. Can anyone please tel me what i'm doing wrong or what i should change. Here's the code: $target_path = "./temp/"; $size = $_SERVER['CONTENT_LENGTH']; if ($size > 2999999) { $_SESSION['msg'] = "Image is to big for upload, please resize image!"; $back = $_SERVER['HTTP_REFERER']; header("location:$back"); break; } ////////////////////////////////////////////////////////// $image = $target_path . basename( $_FILES['image']['name']); // complete image name ////////////// look for the right type of picture //////////////////////// if ($target_path != "") { if(($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"] == "image/png") || ($_FILES["image"]["type"] == "image/jpg")) { $pic = basename( $_FILES['image']['name']); if(!move_uploaded_file($_FILES['image']['tmp_name'], $image)) { $_SESSION['msg'] = "There was an error uploading the file, please try again!"; $back = $_SERVER['HTTP_REFERER']; header("location:$back"); break; } } else { $_SESSION['msg'] = "Invalid image type, please upload a jpeg or png image!"; $back = $_SERVER['HTTP_REFERER']; header("location:$back"); break; } } //////////////////////////////////////////// else { $image = "images/empty.jpg"; // if picture could not be uploaded load dummy picture } ///////// get image type //////////////// list($width, $height) = getimagesize($image); $size = getimagesize($image); $type = explode(".",$image,3); $type = $type[2]; //////////////////////////////////// Resize image en type ///////////////////////// if ($type == "jpg" || $type == "JPG") // if it is a jpeg { $small = "./temp/small.jpg"; $big = "./temp/big.jpg"; $pic_s = resizejpg_small($image); $pic_b = resizejpg_big($image); imagejpeg($pic_s,$small,80); // compress image op 20% imagejpeg($pic_b,$big,80);// compress image op 20% $fp = fopen($small, "rb"); $small = mysql_escape_string(fread($fp, filesize($small))); // makes image blob compatible and $small inserted in db $fp = fopen($big, "rb"); $big = mysql_escape_string(fread($fp, filesize($big))); // makes image blob compatible en $big inserted in db } elseif($type == "png" || $type == "PNG") // if image is png { $small = "./temp/small.png"; $big = "./temp/big.png"; $pic_s = resizepng_small($image); $pic_b = resizepng_big($image); imagepng($pic_s,$small); imagepng($pic_b,$big); $fp = fopen($small, "rb"); $small = mysql_escape_string(fread($fp, filesize($small))); $fp = fopen($big, "rb"); $big = mysql_escape_string(fread($fp, filesize($big))); }
When I saw the title, I already knew what the problem was! ;p Don't EVER rely on $_FILES["image"]["type"]. This value comes from the user and can't be trusted. And besides, IE uses its own content type for some files. Eg .jpg files. Use getimagesize() to get the image type. IMAGETYPE_GIF image/gif IMAGETYPE_JPEG image/jpeg IMAGETYPE_PNG image/png IMAGETYPE_SWF application/x-shockwave-flash IMAGETYPE_PSD image/psd IMAGETYPE_BMP image/bmp IMAGETYPE_TIFF_II (intel byte order) image/tiff IMAGETYPE_TIFF_MM (motorola byte order) image/tiff IMAGETYPE_JPC application/octet-stream IMAGETYPE_JP2 image/jp2 IMAGETYPE_JPX application/octet-stream IMAGETYPE_JB2 application/octet-stream IMAGETYPE_SWC application/x-shockwave-flash IMAGETYPE_IFF image/iff IMAGETYPE_WBMP image/vnd.wap.wbmp IMAGETYPE_XBM image/xbm IMAGETYPE_ICO image/vnd.microsoft.icon Code (markup): http://www.php.net/image-type-to-mime-type