lilnomad
11-21-2006, 01:42 AM
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?
Burhan
11-21-2006, 01:59 AM
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.
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.
lilnomad
11-21-2006, 01:00 PM
here is the 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';
Ks Jeppe
11-21-2006, 05:20 PM
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? :)
brendandonhu
11-21-2006, 06:02 PM
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.
localhost127
11-21-2006, 06:17 PM
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.