hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP - Error in IE but NOT in Mozilla
Reply

Forum Jump

PHP - Error in IE but NOT in Mozilla

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
Junior Guru Wannabe
 
Join Date: Oct 2006
Posts: 31

PHP - Error in IE but NOT in Mozilla


I know PHP is a server side scripting language so this isn't making sense to me. I have an upload script that will upload both jpegs and gifs, and runs smoothly on Mozilla. However on IE it will only take gifs, not jpegs.

I don't even know how to try and trouble shoot this one. Any ideas as to what the problem may be?



Sponsored Links
  #2  
Old
Community Guide
 
Join Date: Jul 2003
Location: Kuwait
Posts: 5,099
Perhaps for some reason IE is not sending the correct headers for jpegs? It all depends on how you are checking the file.

Post some code so we can see what is going on.

__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise

  #3  
Old
Big fan of RajiniKanth!!!
 
Join Date: Sep 2004
Location: Chennai , India
Posts: 4,602
Quote:
Originally Posted by fyrestrtr
Perhaps for some reason IE is not sending the correct headers for jpegs? It all depends on how you are checking the file.

Post some code so we can see what is going on.
yes , i would like to see the code , but i think this could be some other problem.

Sponsored Links
  #4  
Old
Junior Guru Wannabe
 
Join Date: Oct 2006
Posts: 31
here is the code

Code:
// $userfile is where file went on webserver
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];
// $userfile_name is original file name
$userfile_name = $HTTP_POST_FILES['userfile']['name'];
// $userfile_size is size in bytes
$userfile_size = $HTTP_POST_FILES['userfile']['size'];
// $userfile_type is mime type e.g. image/gif
$userfile_type = $HTTP_POST_FILES['userfile']['type'];
// $userfile_error is any error encountered
$userfile_error = $HTTP_POST_FILES['userfile']['error'];

if ($userfile_error > 0)
{
	echo 'Problem: ';
    switch ($userfile_error)
    {
      case 1:  echo 'File exceeded upload_max_filesize';  break;
      case 2:  echo 'File exceeded max_file_size';  break;
      case 3:  echo 'File only partially uploaded';  break;
      case 4:  echo 'No file uploaded';  break;
    }
    exit;
}
  
// does the file have the right MIME type?
if ($userfile_type == 'image/jpeg')
{
	// put the file where we'd like it
	$upfile = '/photos/'.$username.'.jpg';
	// is_uploaded_file and move_uploaded_file added at version 4.0.3

	if (is_uploaded_file($userfile)) 
	{
		if (!move_uploaded_file($userfile, $upfile))
    	{
        	echo 'Problem: Could not move file to destination directory';
        	exit;
    	}
	} 
	else 
	{
    	echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;
    	exit;
	}
	$path = "$username.jpg";
	$insert = "INSERT INTO hotornot (username,path,gender,score,num_of_votes,sum_of_votes) VALUES ('$username','$path','$gender','0','0','0')";
	$result = mysql_query($insert) or die("Error ". mysql_error() ." with query ". $insert);
	
	echo 'File uploaded successfully<br /><br />'; 
	echo $upfile;
	echo "<img src=/photos/$username.jpg>";
}
elseif ($userfile_type == 'image/gif')
{
	// put the file where we'd like it
	$upfile = '/photos/'.$username.'.gif';;
	// is_uploaded_file and move_uploaded_file added at version 4.0.3

	if (is_uploaded_file($userfile)) 
	{
		if (!move_uploaded_file($userfile, $upfile))
    	{
        	echo 'Problem: Could not move file to destination directory';
        	exit;
    	}
	} 
	else 
	{
    	echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;
    	exit;
	}
	echo 'File uploaded successfully<br /><br />'; 
	echo $upfile;
	echo "<img src=/photos/$userfile_name>";
}
else
{
		echo 'Problem: file must either be a GIF or JPEG';
    	exit;
}
and when it runs on IE i get :
echo 'Problem: file must either be a GIF or JPEG';

  #5  
Old
Aspiring Evangelist
 
Join Date: Mar 2006
Posts: 418
Quick and dirty debugging, change echo 'Problem: file must either be a GIF or JPEG'; to echo 'Problem: file must either be a GIF or JPEG, your file was '.$userfile_type; and work of that?

  #6  
Old
Web Hosting Master
 
Join Date: Nov 2003
Posts: 682
IE sends the mime type as image/pjpeg for JPEGs. But that's really not a secure way to check the file types, since the user could upload any file and have their browser call it a GIF or JPEG.

  #7  
Old
Junior Guru
 
Join Date: Sep 2005
Location: Southern California
Posts: 179
Instead of using what the browser sends the image as, use getimagesize() - http://us3.php.net/getimagesize

It will give you an array so you can determine the image type. This way you don't need to worry about browser compat.

Reply

Related posts from TheWhir.com
Title Type Date Posted
New Certificate Authority Wants to Simplify HTTPS Deployment Web Hosting News 2014-11-18 15:54:39
Mozilla Files Petition with FCC to Protect Net Neutrality Web Hosting News 2014-05-05 11:51:21
Mozilla Firefox 23 Will Block Mix SSL Content by Default Web Hosting News 2013-04-12 11:39:07
Mozilla Updates CA Certificate Policy for Software Products Web Hosting News 2013-02-19 12:32:22
Browsers Block Unauthorized Digital Certificate Issued by Turkish CA TURKTRUST Web Hosting News 2013-01-04 12:55:27


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?