Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Works in IE but not in Firefox
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tonberry




PostPosted: Wed Sep 05, 2007 11:49 am   Post subject: Works in IE but not in Firefox

Hi guys,
I wrote a image upload script. It uploads jpg files. If the files is not a jpg file, it generates an error message. This script works perfectly in IE, however in Firefox no matter if the file I try to upload is a jpg file or not, it always gives the wrong file type error message. Can anyone help me fix this issue? Thank you very much! The complete code is here:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Untitled Document</title>
</head>

<body>
<?php
// Where the file is going to be placed
$target_path = "../../temp/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];

$target_path = "../../temp/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if ($_FILES['uploadedfile']['type'] == "image/pjpeg")
{
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "../../temp/ok.jpg")) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded. ";
}

else{
echo "There was an error uploading the file, please try again!";
}
}
else
{
echo "Couldn't upload. File was not jpg type.";
}
?>

</body>
</html>
Sponsor
Sponsor
Sponsor
sponsor
rdrake




PostPosted: Wed Sep 05, 2007 1:01 pm   Post subject: RE:Works in IE but not in Firefox

IE labels JPEG images with image/pjpeg. Every other browser on this Earth labels them image/jpeg. Any browser except IE will see this as an error and reject the image.

Source here.

Edit: So instead of just rejecting anything that doesn't match the "image/pjpeg" MIME type, allow it to check for either image/pjpeg or image/jpeg.
Tonberry




PostPosted: Thu Sep 06, 2007 3:12 pm   Post subject: RE:Works in IE but not in Firefox

Thank you very much!
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: