Strange problem with file upload - works with Firefox but num IE6

Strange problem with file upload - works with Firefox but num IE6

am 14.08.2007 01:05:47 von Macca

Hi people!

I'm having a problem with a file upload script that I'm writing. It
works with Firefox but not Internet explorer.

When the form is submitted(to it's self) it check for a file upload
using this:


$room_type = $_POST['room_type'];
$sleeps = $_POST['sleeps'];
$description = $_POST['description'];
$count = $_POST['count'];
$cost_per_night = $_POST['cost_per_night'];


// ==============
// Configuration
// ==============
$uploaddir = "../account_images"; // Where the files
to upload
//$thumbs_dir ="account_images/thumbs"; // Where the
thumbnail uploads to
// ==============
// Upload Part
// ==============
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
if(($_FILES['file']["type"] == "image/jpeg") ||
($_FILES['file']["type"] == "image/gif") ||
($_FILES['file']["type"] == "image/png"))
{ //200kb
move_uploaded_file($_FILES['file']
['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
$current_file_uploaded = $_FILES['file']
['name'];
$picture_name = $current_file_uploaded;

}
}



Then it runs a function which inputs the info from the form into a db
table like so:

add_room_type_to_db($room_type,$sleeps,$description,$count,
$cost_per_night,$picture_name,$connection);




It works fine when i test it in FF, the image is uploaded and the
image name is inserted into the database, but when i use IE, i get an
E_NOTICE :

"Notice: Undefined variable: picture_name in C:\webserver\webroot
\booking_system\staff\controls.php on line 208"

Line 208 being the line that calls the function "add_room_type_to_db".

Any ideas why this may be happening?

Please help!

Paul

Re: Strange problem with file upload - works with Firefox but num IE6

am 14.08.2007 01:11:24 von luiheidsgoeroe

On Tue, 14 Aug 2007 01:05:47 +0200, macca wro=
te:

> Hi people!
>
> I'm having a problem with a file upload script that I'm writing. It
> works with Firefox but not Internet explorer.
>
> When the form is submitted(to it's self) it check for a file upload
> using this:
>
>
> $room_type =3D $_POST['room_type'];
> $sleeps =3D $_POST['sleeps'];
> $description =3D $_POST['description'];
> $count =3D $_POST['count'];
> $cost_per_night =3D $_POST['cost_per_night'];
>
>
> // ==============
> // Configuration
> // ==============
> $uploaddir =3D "../account_images"; // Where the fil=
es
> to upload
> //$thumbs_dir =3D"account_images/thumbs"; // Where t=
he
> thumbnail uploads to
> // ==============
> // Upload Part
> // ==============
> if(is_uploaded_file($_FILES['file']['tmp_name']))
> {
> if(($_FILES['file']["type"] == "image/jpeg")=
||
> ($_FILES['file']["type"] == "image/gif") =
||
> ($_FILES['file']["type"] == "image/png"))=

> { //200kb
> move_uploaded_file($_FILES['file']
> ['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
> $current_file_uploaded =3D $_FILES['file']
> ['name'];
> $picture_name =3D $current_file_uploaded;
>
> }
> }
> add_room_type_to_db($room_type,$sleeps,$description,$count,
> $cost_per_night,$picture_name,$connection);
>
>
>
>
> It works fine when i test it in FF, the image is uploaded and the
> image name is inserted into the database, but when i use IE, i get an
> E_NOTICE :
>
> "Notice: Undefined variable: picture_name in C:\webserver\webroot
> \booking_system\staff\controls.php on line 208"
>
> Line 208 being the line that calls the function "add_room_type_to_db".=

>
> Any ideas why this may be happening?

The conditional is not run, either because there's no transfer, or the =

mimetype is something you don't expect. print_r($_FILES) to find out.

Also, a 'type' in an upload is something provided by the user and highly=
=

unreliable. For images, I usually use getimagesize() to check wether it'=
s =

recognized as one.
-- =

Rik Wasmus

Re: Strange problem with file upload - works with Firefox but num IE6

am 14.08.2007 01:51:41 von Macca

Hi thanks for the quick reply.

You are right. it was the "type" causing it. I used print_r and it
gave me this:

Array ( [file] => Array ( [name] => DSCF0495.JPG [type] => image/pjpeg
[tmp_name] => C:\WINDOWS\TEMP\php11.tmp [error] => 0 [size] =>
115829 ) )

The type was coming out as "image/pjpeg" for some reason.


I changed it to this and it now works fine. Thanks.


if(is_uploaded_file($_FILES['file']['tmp_name']))
{
print_r($_FILES);
$img_mime_type = getimagesize($_FILES['file']
['tmp_name']);
if(
($img_mime_type[2] == IMAGETYPE_GIF) ||
($img_mime_type[2] == IMAGETYPE_JPEG)||
($img_mime_type[2] == IMAGETYPE_PNG)
)
{ //200kb
move_uploaded_file($_FILES['file']
['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
$current_file_uploaded = $_FILES['file']
['name'];
$picture_name = $current_file_uploaded;

//CREATE THUMBNAIL OF UPLOADED IMAGE
========================= JPG PNG
//createthumb($uploaddir.'/'.
$current_file_uploaded,$uploaddir.'/thumbs/thumb_'.
$current_file_uploaded,150,150);
} else {
die('You may only upload file types
JPEG/JPG, PNG or GIF.');
}

}


Regards,

Paul

Re: Strange problem with file upload - works with Firefox but num IE6

am 14.08.2007 02:08:33 von luiheidsgoeroe

On Tue, 14 Aug 2007 01:51:41 +0200, macca wro=
te:

> Hi thanks for the quick reply.
>
> You are right. it was the "type" causing it. I used print_r and it
> gave me this:
>
> Array ( [file] =3D> Array ( [name] =3D> DSCF0495.JPG [type] =3D> image=
/pjpeg
> [tmp_name] =3D> C:\WINDOWS\TEMP\php11.tmp [error] =3D> 0 [size] =3D>
> 115829 ) )
>
> The type was coming out as "image/pjpeg" for some reason.
>
>
> I changed it to this and it now works fine. Thanks.
>
>
> if(is_uploaded_file($_FILES['file']['tmp_name']))
> {
> print_r($_FILES);
> $img_mime_type =3D getimagesize($_FILES['file']
> ['tmp_name']);
> if(
> ($img_mime_type[2] == IMAGETYPE_GIF) ||
> ($img_mime_type[2] == IMAGETYPE_JPEG)||
> ($img_mime_type[2] == IMAGETYPE_PNG)
> )

I'd use:

if($img_mime_type && ($img_mime_type[2] == IMAGETYPE_GIF || =

$img_mime_type[2] == IMAGETYPE_JPEG || $img_mime_type[2] == IMAG=
ETYPE_PNG))

As getimagesize() will return false for something not recognized as an =

image.
-- =

Rik Wasmus