Upload script not working with IE

Discussion in 'PHP' started by sittsait, Jul 31, 2008.

  1. #1
    This needs quite fast fixing. :eek:
    Works fine in FF but echos negative when using IE saying that only .jpg files are allowed.

    Anyway i use 2 php files to upload files into directories:

    1st - uploading.php
    <html><title>Faili laadimine</title>
    <body>
    <?php require_once "../../maincore.php"; ?>
    <?php if (iMEMBER) {
      echo "<form enctype='multipart/form-data' action='upload.php' method='post'>";
        echo "<input type='hidden' name='MAX_FILE_SIZE' value='1000000' />";
        echo "Vali pilt (jpg): ";
        echo "<input name='uploaded_file' type='file' />";
        echo "<input type='submit' value='Saada' />";
      echo "</form>";
    }else{ echo "<img src='".BASEDIR."images/main/negative.png'> Mängude üleslaadimiseks logi sisse.";}
    ?>
    </body>
    </html>
    Code (markup):

    2nd - upload.php
    <?php
    require_once "../../maincore.php";
    //Сheck that we have a file
    if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
      //Check if the file is JPEG image and it's size is less than 100Kb
      $filename = basename($_FILES['uploaded_file']['name']);
      $ext = substr($filename, strrpos($filename, '.') + 1);
      if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
        ($_FILES["uploaded_file"]["size"] < 100000)) {
        //Determine the path to which we want to save this file
          $newname = dirname(__FILE__).'/files/'.$filename;
          //Check if the file with the same name is already exists on the server
          if (!file_exists($newname)) {
            //Attempt to move the uploaded file to it's new place
            if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
               echo "<img src='".BASEDIR."images/main/positive.png'> Pilt on edukalt saadetud!";
            }
          } else {
            echo "<img src='".BASEDIR."images/main/negative.png'> Antud failinimi ".$_FILES["uploaded_file"]["name"]." on juba kasutusel!";
          }
      } else {
         echo "<img src='".BASEDIR."images/main/negative.png'>  Ainult .jpg formaadis pildid maksimaalse suurusega 100kb!";
      }
    } else {
     echo "<img src='".BASEDIR."images/main/negative.png'>  Faili ei saadetud!";
    }
    ?>
    Code (markup):
    UPLOAD.PHP contains code to generate form.
    UPLOADING.PHP system file for upload.php: file checking, size checking, general upload code etc.
     
    sittsait, Jul 31, 2008 IP
  2. klimu

    klimu Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If I do remember correctly IE creates it's own MIME type for jpg pictures.. (image/pjpeg or something similar). Try to print_r the $_FILES array to see what it actually is.
     
    klimu, Jul 31, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    ^ Yep, that's the problem.

    And you should not rely on the MIME type of the $_FILES array anyway, because it comes from the user's browser and can be easily faked.
     
    nico_swd, Jul 31, 2008 IP
  4. klimu

    klimu Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you really should use getimagesize() to figure out mime type
     
    klimu, Jul 31, 2008 IP