my upload form doe not work on IE?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

my upload form doe not work on IE?

Post by saumya »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi ppl,
I am having a strange problem here.
I have an image upload form, that works nicely from Firefox, but it doe not work in IE?
The code is below

Code: Select all

$upload_error=$_FILES['photo']['error'];
		switch($upload_error) {
			case 0: //no error; possible file attack!
				echo 'no error; possible file attack!';
				break;
			case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
				echo 'uploaded file exceeds the upload_max_filesize directive in php.ini';
				break;
			case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
				echo 'uploaded file exceeds the MAX_FILE_SIZE ( 10 KB ) directive that was specified in the html form';
				break;
			case 3: //uploaded file was only partially uploaded
				echo 'uploaded file was only partially uploaded';
				break;
			case 4: //no file was uploaded
				//$error = $error . $upload_error . ": " . $upload_error_lang[$upload_error];
				echo 'no file was uploaded';
				break;
			default: //a default error, just in case!  
				$error ="<br/><br/>". $error . $upload_error . ": " . $upload_error_gen_lang;
				break;
		}
it always goes into the default block in IE !!
If you want I can give you the URL to test too.
saumya


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

Post by ryuuka »

can you give us the link and the code where you give the file to upload
and where you move the file to the server etc
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok, here is the link

http://www.subhvivaah.in/sam_simple_cms/admin.php

the code is below

Code: Select all

$upload_error=$_FILES['photo']['error'];
		switch($upload_error) {
			case 0: //no error; possible file attack!
				echo 'no error; possible file attack!';
				break;
			case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
				echo 'uploaded file exceeds the upload_max_filesize directive in php.ini';
				break;
			case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
				echo 'uploaded file exceeds the MAX_FILE_SIZE ( 10 KB ) directive that was specified in the html form';
				break;
			case 3: //uploaded file was only partially uploaded
				echo 'uploaded file was only partially uploaded';
				break;
			case 4: //no file was uploaded
				//$error = $error . $upload_error . ": " . $upload_error_lang[$upload_error];
				echo 'no file was uploaded';
				break;
			default: //a default error, just in case!  
				$error ="<br/><br/>". $error . $upload_error . ": " . $upload_error_gen_lang;
				break;
		}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
shwanky
Forum Commoner
Posts: 45
Joined: Thu Feb 15, 2007 1:21 am

Post by shwanky »

saumya wrote:ok, here is the link

http://www.subhvivaah.in/sam_simple_cms/admin.php

the code is below

Code: Select all

$upload_error=$_FILES['photo']['error'];
		switch($upload_error) {
			case 0: //no error; possible file attack!
				echo 'no error; possible file attack!';
				break;
			case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
				echo 'uploaded file exceeds the upload_max_filesize directive in php.ini';
				break;
			case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
				echo 'uploaded file exceeds the MAX_FILE_SIZE ( 10 KB ) directive that was specified in the html form';
				break;
			case 3: //uploaded file was only partially uploaded
				echo 'uploaded file was only partially uploaded';
				break;
			case 4: //no file was uploaded
				//$error = $error . $upload_error . ": " . $upload_error_lang[$upload_error];
				echo 'no file was uploaded';
				break;
			default: //a default error, just in case!  
				$error ="<br/><br/>". $error . $upload_error . ": " . $upload_error_gen_lang;
				break;
		}
The error is in your javascript. The IE debugger said there error was on line 17.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

Use the constants UPLOAD_ERR_OK etc. instead of hardcoded values.
case 0: //no error; possible file attack!
Whatever gave you the idea?!
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

Hi,
thanks buddy. But I do not get the idea :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Zero is used when there were no errors (as far as PHP is concerned.)
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

But why was it is not working on IE when its working on Firefox. !!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

The error is in your javascript. The IE debugger said there error was on line 17.
IE doesn't handle JavaScript errors as well as Firefox.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

so, whats the fix?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Fix the errors?
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

i do not understand now, what to fix?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

The error is in your javascript. The IE debugger said there error was on line 17.
... Fix the errors ... The errors in your javascript is what's causing the problem... fix those errors, and it will work.

IE stops processing when it finds and error, Firefox doesn't.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

thanks buddy.
I will give it a try and come back here.
8O
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

hi guys,
I got it worked in both the browsers and the problem was with the handling of JPEGs in PHP.

I have modified the PHP code to upload GIFs ( suggested by a friend in another forum ) and now it works in both the browsers.

But handling JPEGs is still an issue.

The modified code

Code: Select all

if($_FILES['photo']['type'] == "image/gif"){
	
	//First check whether upload has been success ful or not
		if(is_uploaded_file($_FILES['photo']['tmp_name'])){
		//Add the original filename to our target path. Result is "uploads/filename.extension" 
		//Renaming to my preffered name after the file has been uploaded
		$target_path = $target_path . $filename.'.gif'; 
			if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) {
				echo " The file ".  basename( $_FILES['photo']['name'])." has been <b>successfully uploaded</b>";
			} else{
				echo "There was an error uploading the file, please try again!";
			}
		}else{
			echo $_FILES['photo']['error'];
		}


For JPEGs we thought of the below code

Code: Select all

if ($_FILES["photo"]["type"] == "image/jpeg" ){
//UPLOAD CODE FOR IE
}
elseif ($_FILES["photo"]["type"] == "jpeg" ){
//UPLOAD CODE FOR FF
}
Post Reply