SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Question Form Input File Type ... ugg

    I am using a form to upload a file... pretty simple. Everything works except for restricting the file type the user is allowed to upload. Here's my code:

    <form action="uploadphotoscript.php?name=<?=$name?>" method="post" enctype="multipart/form-data">
    <p><font color="#000000">Name of image: <input type="text" name="name">
    <p><font color="#000000">Select image file (.jpg ONLY): <input type="file" accept="image/jpg,jpeg" name="uploadedfile">
    <p><br><p>
    <input type="submit" name="image" value="Upload Photo"></form>

    It's not restricting the file type. Any ideas what I'm doing wrong?
    TAKE A WALK OUTSIDE YOUR MIND.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should use a server side language to check this.

    it should be a comma separated list of mime types

    Code:
    <input type="file" accept="image/jpeg" name="uploadedfile">
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    How would I do that? When I Google this subject, it looks like I'm doing everything properly.

    The link you posted is just for MIME types, no?
    TAKE A WALK OUTSIDE YOUR MIND.

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    That makes more sense how to validate the file with PHP, but I guess my question is how to limit the user from even selecting a file other than what I specify in the first place.

    When they click on Browse... I want that drop menu at the bottom to only show .jpg files, or .pdf files. Granted I could validate them later, I would rather the user doesn't have that option to begin with.

    Maybe I'm totally missing the entire point of this, but I thought I could specify the type of file that would show in the "Choose File" dialog box.
    TAKE A WALK OUTSIDE YOUR MIND.

  6. #6
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wish that were possible.

    However, even if you could, there is still a way that a user could specify a file with a different extension.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  7. #7
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use this and wait till browsers support it.
    HTML Code:
    <input name="file" type="file" accept="application/pdf,image/jpeg">
    See Mozilla bug #83749 and the HTML4 spec.
    Simon Pieters


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
  •