SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict dbr's Avatar
    Join Date
    Aug 2006
    Location
    Tucked away in the mountains...
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP "If" statement works in firefox, but not IE7

    With FireFox I get inside the "IF" statement, With IE7 I always get invalid file.
    Any help appreciated
    PHP Code:
    <?php
    # file uploads images okay in firefox, but not IE7...:-( bug found: 7-2-07
    # file name: getimage.php
    if (($_FILES["file"]["type"] == "image/jpeg")
    && (
    $_FILES["file"]["size"] <= 105000)) //max img size 100k room for a little slop.
      
    {
          echo 
    'If file valid place code to execute here.'
       }

    else
      {
      echo 
    "Invalid file";
      }
    ?>
    This is the file I use to call the above PHP file to get the image.
    HTML Code:
    <html>
    <head>
    <title>ImageUpload</title>
    </head>
    <body>
    <fieldset><legend>Step 1 Acquire Image</legend>
    <form action="getimage.php" method="post"
    enctype="multipart/form-data"><br />
    <input type="file" name="file" id="file" /> 
    <br />
    <input type="submit" name="submit" value="Acquire Photo" />
    </form>
    
    <h3>Restrictions</h3>
    <ol>
    <li>File Type: jpeg</li>
    <li>Maximum Size: 100 kilobytes</li>
    </ol>
    
    </fieldset>
    </body>
    </html>
    "Three components make an entrepreneur:
    the person, the idea, and the resources to make it happen."
    Anita Roddick ~British entrepreneur
    dbr founder of: ProximityCast.com

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try different MIME types, image/pjpeg, image/jpg. Also try print_r($_FILES) and see what does it output.
    Saul

  3. #3
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never rely on $_FILES["file"]["type"] for your validation - you're in fact seeing exactly why: Firefox is telling you it's "image/jpeg", while IE is saying that it's "image/pjpeg" (most likely). $_FILES["file"]["type"] is user-supplied, and thus entirely untrustworthy. Better would be to use getimagesize instead; I would also use filesize instead of $_FILES["file"]["size"].
    PHP questions? RTFM
    MySQL questions? RTFM

  4. #4
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Also try print_r($_FILES) and see what does it output.
    Yes, do this. Those array values are supplied by the browser and shouldn't be relied upon. IE 7 may not be sending them. Always use the built-in PHP error codes for file uploads, and always verify the MIME type in PHP (e.g., with mime_content_type in PHP 4 or the finfo_x functions in PHP 5).

    Also, the required hidden MAX_FILE_SIZE field is missing from your HTML form.

  5. #5
    SitePoint Addict dbr's Avatar
    Join Date
    Aug 2006
    Location
    Tucked away in the mountains...
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Thanks!

    Quote Originally Posted by php_daemon View Post
    Try different MIME types, image/pjpeg, image/jpg. Also try print_r($_FILES) and see what does it output.
    The MIME type did it! Much appreciated!!
    "Three components make an entrepreneur:
    the person, the idea, and the resources to make it happen."
    Anita Roddick ~British entrepreneur
    dbr founder of: ProximityCast.com


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
  •