This is a discussion on Strange problem with file upload - works with Firefox but num IE6 within the PHP Language forums, part of the PHP Programming Forums category; Hi people! I'm having a problem with a file upload script that I'm writing. It works with Firefox ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
On Tue, 14 Aug 2007 01:05:47 +0200, macca <ptmcnally@googlemail.com> wrote:
> 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 |
|
|||
|
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 |
|
|||
|
On Tue, 14 Aug 2007 01:51:41 +0200, macca <ptmcnally@googlemail.com> wrote:
> 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 |