Page 1 of 2

my upload form doe not work on IE?

Posted: Fri Feb 16, 2007 1:01 am
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]

Posted: Fri Feb 16, 2007 1:26 am
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

Posted: Fri Feb 16, 2007 1:29 am
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]

Posted: Fri Feb 16, 2007 3:14 am
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.

Posted: Fri Feb 16, 2007 5:14 am
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?!

Posted: Sat Feb 17, 2007 12:08 pm
by saumya
Hi,
thanks buddy. But I do not get the idea :(

Posted: Sat Feb 17, 2007 12:35 pm
by feyd
Zero is used when there were no errors (as far as PHP is concerned.)

Posted: Sat Feb 17, 2007 1:01 pm
by saumya
But why was it is not working on IE when its working on Firefox. !!

Posted: Sat Feb 17, 2007 2:18 pm
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.

Posted: Sat Feb 17, 2007 9:19 pm
by saumya
so, whats the fix?

Posted: Sat Feb 17, 2007 9:20 pm
by nickvd
Fix the errors?

Posted: Sat Feb 17, 2007 9:25 pm
by saumya
i do not understand now, what to fix?

Posted: Sat Feb 17, 2007 9:33 pm
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.

Posted: Sat Feb 17, 2007 9:38 pm
by saumya
thanks buddy.
I will give it a try and come back here.
8O

Posted: Mon Feb 26, 2007 6:15 am
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
}