Jump to content

Image Upload - Quick Question


Ell20

Recommended Posts

Hi,

 

I have a fully working image upload script, in Mozilla Firefox, however if I attempt to upload images in Internet Explorer it dosent like it and says Picture not uploaded, wrong file type.

 

It only seems to occur with JPG, JPEGS.

 

if($_POST['changeimage']){
$tab1=0;
$tab3=1;
$tab2=0;
$tab4=0;
$tab5=0;

list($width, $height) = getimagesize($_FILES['imagefile']['tmp_name']);

if ($width <= 350 && $height <= 300) {
if (($_FILES['imagefile']['type'] == "image/jpeg") || ($_FILES["imagefile"]["type"] == "image/gif") || ($_FILES["imagefile"]["type"] == "image/png")) {
copy ($_FILES['imagefile']['tmp_name'], "/home/scrpgco/public_html/images/profiles/".$_FILES['imagefile']['name'] = md5($_FILES['imagefile']['name'] . rand()) . $_FILES['imagefile']['name']) or die ("Could not copy");
$message = "Picture Uploaded!";
if($userinfo['profimage']!=""){
$location = $userinfo['profimage'];
$file_delete = "/home/scrpgco/public_html/images/profiles/$location";
unlink($file_delete);
updatedata($id,"profimage=''");
}
updatedata($id,"profimage='{$_FILES['imagefile']['name']}'");
} else {
$message = "Picture not uploaded, wrong filetype (".$_FILES['imagefile']['name'].")";
}
} else {
$message=  "Picture not uploaded, picture dimensions are too big (".$_FILES['imagefile']['name'].")";
}
}

 

Can anyone shed any light as to why this might work in Mozilla but not IE?

 

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/93216-image-upload-quick-question/
Share on other sites

This is what got returned when it fails:

 

Array ( [imagefile] => Array ( [name] => new.jpeg [type] => image/pjpeg [tmp_name] => /tmp/php2lvzG1 [error] => 0 => 3003 ) )

Well since it returned [type] => image/pjpeg,

 

Which is something that is not on your approved file header list, you have to add it.

 

if (($_FILES['imagefile']['type'] == "image/jpeg") || ($_FILES["imagefile"]["type"] == "image/gif") || ($_FILES["imagefile"]["type"] == "image/png") || ($_FILES["imagefile"]["type"] == "image/pjpeg"))

 

New Code:

<?php
if($_POST['changeimage']){
$tab1=0;
$tab3=1;
$tab2=0;
$tab4=0;
$tab5=0;

list($width, $height) = getimagesize($_FILES['imagefile']['tmp_name']);

if ($width <= 350 && $height <= 300) {
if (($_FILES['imagefile']['type'] == "image/jpeg") || ($_FILES["imagefile"]["type"] == "image/gif") || ($_FILES["imagefile"]["type"] == "image/png") || ($_FILES["imagefile"]["type"] == "image/pjpeg")) {
copy ($_FILES['imagefile']['tmp_name'], "/home/scrpgco/public_html/images/profiles/".$_FILES['imagefile']['name'] = md5($_FILES['imagefile']['name'] . rand()) . $_FILES['imagefile']['name']) or die ("Could not copy");
$message = "Picture Uploaded!";
if($userinfo['profimage']!=""){
$location = $userinfo['profimage'];
$file_delete = "/home/scrpgco/public_html/images/profiles/$location";
unlink($file_delete);
updatedata($id,"profimage=''");
}
updatedata($id,"profimage='{$_FILES['imagefile']['name']}'");
} else {
$message = "Picture not uploaded, wrong filetype (".$_FILES['imagefile']['name'].")";
}
} else {
$message=  "Picture not uploaded, picture dimensions are too big (".$_FILES['imagefile']['name'].")";
}
}
?>

Just a quick simplifying option for you.

 

Instead of

if(something = blah blah OR something = blah blah OR something = blah blah)

try

$arr = array("blah blah", "blah blah", "blah blah");
if(in_array("something", $arr);

 

It then means if you start doing the lookups for accepted types from a database, then all you need to do is build the array ($arr) and viola it works.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.