HighDots Forums  

<input type=file ...>

HTML Writing HTML for the Web (comp.infosystems.www.authoring.html)


Discuss <input type=file ...> in the HTML forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
magix
 
Posts: n/a

Default <input type=file ...> - 02-21-2008 , 12:21 PM






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



Reply With Quote
  #2  
Old   
Rik Wasmus
 
Posts: n/a

Default Re: <input type=file ...> - 02-21-2008 , 01:56 PM






On Thu, 21 Feb 2008 18:21:40 +0100, magix <magix (AT) asia (DOT) com> wrote:
Quote:
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


Reply With Quote
  #3  
Old   
Rik Wasmus
 
Posts: n/a

Default Re: <input type=file ...> - 02-21-2008 , 01:58 PM



On Thu, 21 Feb 2008 19:56:26 +0100, Rik Wasmus
<luiheidsgoeroe (AT) hotmail (DOT) com> wrote:
Quote:
(varying from just type to selecting while directories
....varying from just extensions, to selecting whole directorie.
--
Rik Wasmus


Reply With Quote
  #4  
Old   
GTalbot
 
Posts: n/a

Default Re: <input type=file ...> - 02-21-2008 , 06:19 PM



On 21 fév, 12:21, "magix" <ma... (AT) asia (DOT) com> wrote:

Quote:
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").
http://www.w3.org/TR/html4/interact/...ml#adef-accept

So:

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

Not tested.

Gérard


Reply With Quote
  #5  
Old   
Jonathan N. Little
 
Posts: n/a

Default Re: <input type=file ...> - 02-21-2008 , 07:36 PM



GTalbot wrote:
Quote:
On 21 fév, 12:21, "magix" <ma... (AT) asia (DOT) 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.

Quote:
prompting a user to select files to be sent to the server (cf. the
INPUT element when type="file").
http://www.w3.org/TR/html4/interact/...ml#adef-accept

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
http://www.LittleWorksStudio.com


Reply With Quote
  #6  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: <input type=file ...> - 02-22-2008 , 03:27 AM



Scripsit Stephan Bird:

Quote:
input type="file" accept="image/jpg, image/gif"

Not tested.

This seems to rely on MIME types (amongst other things),
MIME types would be the right concept to be used, but as Jonathan
mentioned, this attribute has not been implemented. There's a lot in
file input that exists only in the original plans and later
specifications and was ignored or distorted by implementors; see
http://www.cs.tut.fi/~jkorpela/forms/file.html

Quote:
so in
principle could I send a file abc which is encoded as a gif or jpeg
and have it accepted?
In principle, yes. However, image/jpg is an unregistered MIME type; this
was probably a typo, and image/jpeg was intended. If image/jpg were
actually used, it would be ignored by a conforming implementation, and
GIF images only would be accepted.

Quote:
If the string above worked and no others, what
of image/jpeg or image/jpe - are these also encoded by the same
codex?
The correct MIME type name is image/jpeg, and image/jpg and image/jpe
are undefined and to be ignored. However, a quality implementation would
issue a warning and prompt the user for corrective action and send a
message to the page author, if specified in metadata, and then cows
would fly.

Quote:
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..?
The last three letters of a filename are no magic. Programs may assume
some mapping from them to MIME types, but there is no specification on
this, and there is great variation in practice.

A proper implementation of accept="..." would require, more or less, a
file system where each file has a descriptor indicating its properties,
such as MIME type (and character encoding, etc.). Simple filtering by
filename extension would be easy to implement but somewhat problematic;
in practice, implementors just didn't bother.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.