<input type=file ...>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • magix

    <input type=file ...>

    Hi,

    with:
    <Input type="file"...>

    it will let the user to click to "browse" button to browse for files,
    question is how can I limit the file type to be only jpg and gif extension,
    when the browse window open ?

    thank you.

    Regards,
    Magix


  • Rik Wasmus

    #2
    Re: &lt;input type=file ...&gt;

    On Thu, 21 Feb 2008 19:56:26 +0100, Rik Wasmus
    <luiheidsgoeroe @hotmail.comwro te:
    (varying from just type to selecting while directories
    ....varying from just extensions, to selecting whole directorie.
    --
    Rik Wasmus

    Comment

    • Rik Wasmus

      #3
      Re: &lt;input type=file ...&gt;

      On Thu, 21 Feb 2008 18:21:40 +0100, magix <magix@asia.com wrote:
      with:
      <Input type="file"...>
      >
      it will let the user to click to "browse" button to browse for files,
      question is how can I limit the file type to be only jpg and gif
      extension,
      when the browse window open ?
      Nope, not a widely supported anyway, I seem to remember some browser
      specific options, but they don't play nice together. If this is a must,
      look into a flash (or possibly java) uploader, which can be more
      controlled (varying from just type to selecting while directories/mulitple
      files at once). Be sure to provide a clean HTML fallback.
      --
      Rik Wasmus

      Comment

      • GTalbot

        #4
        Re: &lt;input type=file ...&gt;

        On 21 fév, 12:21, "magix" <ma...@asia.com wrote:
        how can I limit the file type to be only jpg and gif extension,
        when the browse window open ?
        accept = content-type-list [CI]
        This attribute specifies a comma-separated list of content types
        that a server processing this form will handle correctly. User agents
        may use this information to filter out non-conforming files when
        prompting a user to select files to be sent to the server (cf. the
        INPUT element when type="file").


        So:

        <input type="file" accept="image/jpg, image/gif">

        Not tested.

        Gérard

        Comment

        • Jonathan N. Little

          #5
          Re: &lt;input type=file ...&gt;

          GTalbot wrote:
          On 21 fév, 12:21, "magix" <ma...@asia.com wrote:
          >
          >how can I limit the file type to be only jpg and gif extension,
          >when the browse window open ?
          >
          accept = content-type-list [CI]
          This attribute specifies a comma-separated list of content types
          that a server processing this form will handle correctly. User agents
          may use this information to filter out non-conforming files when
          ^^^^
          The operative word is "may" and *none* of the browsers I have FF,
          SeaMonkey, Opera, IE and old Netscape do.
          prompting a user to select files to be sent to the server (cf. the
          INPUT element when type="file").

          >
          So:
          >
          <input type="file" accept="image/jpg, image/gif">
          >
          Not tested.
          The only way check at the receiving server side script. You can use the
          option of additionally prescreening the selection with JavaScript.

          --
          Take care,

          Jonathan
          -------------------
          LITTLE WORKS STUDIO

          Comment

          • Stephan Bird

            #6
            Re: &lt;input type=file ...&gt;

            On Thu, 21 Feb 2008 15:19:30 -0800 in
            b0f69bfa-5ce3-46f4-a22c-960a64330b16...l egroups.com GTalbot
            <newsgroup@gtal bot.orgwrote:
            On 21 fév, 12:21, "magix" <ma...@asia.com wrote:
            >
            >how can I limit the file type to be only jpg and gif extension, when
            >the browse window open ?
            >
            accept = content-type-list [CI]
            This attribute specifies a comma-separated list of content types
            that a server processing this form will handle correctly. User agents
            may use this information to filter out non-conforming files when
            prompting a user to select files to be sent to the server (cf. the INPUT
            element when type="file").

            >
            So:
            >
            <input type="file" accept="image/jpg, image/gif">
            >
            Not tested.
            This seems to rely on MIME types (amongst other things), so in principle
            could I send a file abc which is encoded as a gif or jpeg and have it
            accepted? If the string above worked and no others, what of image/jpeg or
            image/jpe - are these also encoded by the same codex? To the strict
            letter of the OP, perhaps all you need to do is check the last three
            letters of the filename, but that may run into issues with things like
            def.gif which is actually an executable..?

            Stephan

            --
            Stephan Bird MChem(Hons) AMRSC
            stephan.j.bird@ mad.scientist.c omREMOVE
            Currently in Caernarfon, Wales.

            Comment

            Working...