Results 1 to 7 of 7
-
11-21-2006, 01:42 AM #1Junior 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?
-
11-21-2006, 01:59 AM #2Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
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.
-
11-21-2006, 06:05 AM #3Big fan of RajiniKanth!!!
- Join Date
- Sep 2004
- Location
- Chennai , India
- Posts
- 4,632
Originally Posted by fyrestrtr
-
11-21-2006, 01:00 PM #4Junior 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; }
echo 'Problem: file must either be a GIF or JPEG';
-
11-21-2006, 05:20 PM #5Aspiring Evangelist
- Join Date
- Mar 2006
- Posts
- 421
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?
-
11-21-2006, 06:02 PM #6Web Hosting Master
- Join Date
- Nov 2003
- Posts
- 691
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.
-
11-21-2006, 06:17 PM #7Junior 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.