SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Mo Money's Avatar
    Join Date
    Nov 2002
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy $_FILES['image_name']['type'] PROBLEMS

    I am making an image upload form, and, I am having one annoying problem.


    PHP Code:

    <?php

    if ($_FILES['icon_file']['type'] != "image/gif") {
    echo 
    "File WAS NOT UPLOADED: "$_FILES['icon_file']['type'] ."";
    exit();
    } else {
    exit(
    "File Was Uploaded");
    }

    ?>
    ^^ Simplified version minus the actual uploading part ^^

    I am trying to make it so you can only upload a gif. But whenever I submit a .gif or any other file, it always echos File WAS NOT UPLOADED, but then it says its an image/gif!?!? I think the problem is with the != because this works in determining if it was a gif:

    PHP Code:

    <?php

    if ($_FILES['icon_file']['type'] == "image/gif") {
    exit(
    "File Was Uploaded");
    } else {
    echo 
    "File WAS NOT UPLOADED: "$_FILES['icon_file']['type'] ."";
    exit();
    }

    ?>
    Anyone know?
    AbcArcade.com - free internet games!

  2. #2
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have had numerous people get snags with ['type'] returns (strangely they vary dependent upon client platform and browser). You are better off trying to determine the type through a seperate function call on the ['tmp_name'] variable - I'd suggest getImageSize for determining a gif

    $file_refs = getImageSize($_FILES['icon_file']['tmp_name']);
    if($file_refs[2] == 1) { echo 'here be gif';}

    $file_refs[0] = image width
    $file_refs[1] = image height
    $file_refs[2] = image type (1=gif, 2=jpg, 3=png, 4=swf, 0=not an image)
    $file_refs[3] = string ('width="nn" height="mm"')
    teckis - that's news to me.


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
  •