SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Picture upload problem with IE

    hi there,

    can anyone please help me with this problem!!!
    my picture upload code works fine in firefox but doesn't seem to work in IE.

    Can anyone please tel me what i'm doing wrong or what i should change.

    Here's the code:
    $target_path = "./temp/";

    $size = $_SERVER['CONTENT_LENGTH'];
    if ($size > 2999999)
    {
    $_SESSION['msg'] = "Image is to big for upload, please resize image!";
    $back = $_SERVER['HTTP_REFERER'];
    header("location:$back");
    break;
    }
    //////////////////////////////////////////////////////////

    $image = $target_path . basename( $_FILES['image']['name']); // complete image name

    ////////////// look for the right type of picture ////////////////////////
    if ($target_path != "")
    {
    if(($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"] == "image/png") || ($_FILES["image"]["type"] == "image/jpg"))
    {
    $pic = basename( $_FILES['image']['name']);

    if(!move_uploaded_file($_FILES['image']['tmp_name'], $image))
    {
    $_SESSION['msg'] = "There was an error uploading the file, please try again!";
    $back = $_SERVER['HTTP_REFERER'];
    header("location:$back");
    break;
    }
    }
    else
    {
    $_SESSION['msg'] = "Invalid image type, please upload a jpeg or png image!";
    $back = $_SERVER['HTTP_REFERER'];
    header("location:$back");
    break;
    }
    }
    ////////////////////////////////////////////
    else
    {
    $image = "images/empty.jpg"; // if picture could not be uploaded load dummy picture
    }
    ///////// get image type ////////////////
    list($width, $height) = getimagesize($image);
    $size = getimagesize($image);
    $type = explode(".",$image,3);
    $type = $type[2];

    //////////////////////////////////// Resize image en type /////////////////////////

    if ($type == "jpg" || $type == "JPG") // if it is a jpeg
    {
    $small = "./temp/small.jpg";
    $big = "./temp/big.jpg";
    $pic_s = resizejpg_small($image);
    $pic_b = resizejpg_big($image);

    imagejpeg($pic_s,$small,80); // compress image op 20%
    imagejpeg($pic_b,$big,80);// compress image op 20%

    $fp = fopen($small, "rb");
    $small = mysql_escape_string(fread($fp, filesize($small))); // makes image blob compatible and $small inserted in db
    $fp = fopen($big, "rb");
    $big = mysql_escape_string(fread($fp, filesize($big))); // makes image blob compatible en $big inserted in db
    }
    elseif($type == "png" || $type == "PNG") // if image is png
    {
    $small = "./temp/small.png";
    $big = "./temp/big.png";
    $pic_s = resizepng_small($image);
    $pic_b = resizepng_big($image);

    imagepng($pic_s,$small);
    imagepng($pic_b,$big);

    $fp = fopen($small, "rb");
    $small = mysql_escape_string(fread($fp, filesize($small)));
    $fp = fopen($big, "rb");
    $big = mysql_escape_string(fread($fp, filesize($big)));
    }

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    "doesn't seem to work" is not a sufficient problem description when asking people to help you

    In what way doesn't it work? What parts of the code do work in IE and what parts don't? What have you done so far to troubleshoot?

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dan,

    I'm sorry for the bad post I left if still new with this.

    Ok the code should upload the picture to my mySQL database and it does all this in firefox.

    But if you test the same code in IE it doesn't want to upload the picture, and stops the browser where the code is located.

    If I delete the upload code the browser continues doing what is should accept no picture is uploaded.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What part is the upload code? (The upload actually happens before your script is run at all)

    What do you see when you dump $_FILES? Does it contain what you expect?

    What does the form submitting to this page look like? Does it have the right enctype?

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add the ability to upload 'image/pjpeg' images. IE will detect jpeg images as progressive jpg images if i remember correctly, which have their own mime type in IE. For added security, the script should also check the extension of the file and not just the mime type when you upload it .

    Not sure if this is the problem, but it's something I noticed in your script.

  6. #6
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Thank you Dorza,

    I've implemented 'image/pjpeg' and now the code word perfectly.
    Thank you very much for your post.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •