473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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,$descriptio n,$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

Aug 13 '07 #1
3 2264
Rik
On Tue, 14 Aug 2007 01:05:47 +0200, macca <pt*******@googlemail.comwrote:
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;

}
}
add_room_type_to_db($room_type,$sleeps,$descriptio n,$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
Aug 13 '07 #2
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

Aug 13 '07 #3
Rik
On Tue, 14 Aug 2007 01:51:41 +0200, macca <pt*******@googlemail.comwrote:
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)
)
I'd use:

if($img_mime_type && ($img_mime_type[2] == IMAGETYPE_GIF ||
$img_mime_type[2] == IMAGETYPE_JPEG || $img_mime_type[2] == IMAGETYPE_PNG))

As getimagesize() will return false for something not recognized as an
image.
--
Rik Wasmus
Aug 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just...
1
by: Stijn Goris | last post by:
hi all, I have a form containing text input, checkboxes and a file upload (all in one form). The file has the a name = foto. When I try to check the name of the file in nieuwsVoegToe.php I get...
2
by: Dynamo | last post by:
Hi all Further to my earlier posting and the advice recieved I have now modified my code but it still doesn't work. I am trying to upload a file from my local PC to my remote server by using a...
2
by: Andrea Williams | last post by:
i was able to get the file upload to work on Win2k, but when I moved my dev environment to Win2003, I can't seem to get the permissions to work for...
3
by: IRAS Blues | last post by:
Hi all, I've got a form that consists of a bunch of textboxes and also file upload inputs. For both sets of fields, I need to be able to add in additional elements on the fly. This is done by an...
0
by: Benjamin Bittner | last post by:
Hallo NG, ive searched a lot in some google groups, and found many threads, but nothing that helped me. Here is the scenario: I have an aspx page which loads a user control in page.onInit like...
13
by: db | last post by:
Hi@all, I am always thinking that there is no problems that I can not solve. But now i changed my idea...... And I have posted it in javascript group, since i think both javascript and php...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
9
by: Arthur Jacobs | last post by:
Good Day, I can upload a file as long as it is empty (thanks Hendri Kurniawan). I do not know where to look. Can someone help me understand what I need to do to upload a small image....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.