Jump to content

Trouble Shooting - Upload Script


lilman

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/27942-trouble-shooting-upload-script/
Share on other sites

[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;
}
[/code]

The error I get is: Problem: file must either be a GIF or JPEG and that is only when I try to upload a jpeg on IE, on Mozilla it works fine without no errors.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.