By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,613 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,613 IT Pros & Developers. It's quick & easy.

<input type=file ...>

P: n/a
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
Feb 21 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Thu, 21 Feb 2008 19:56:26 +0100, Rik Wasmus
<lu************@hotmail.comwrote:
(varying from just type to selecting while directories
....varying from just extensions, to selecting whole directorie.
--
Rik Wasmus
Feb 21 '08 #2

P: n/a
On Thu, 21 Feb 2008 18:21:40 +0100, magix <ma***@asia.comwrote:
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
Feb 21 '08 #3

P: n/a
On 21 fév, 12:21, "magix" <ma...@asia.comwrote:
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
Feb 21 '08 #4

P: n/a
GTalbot wrote:
On 21 fév, 12:21, "magix" <ma...@asia.comwrote:
>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").
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
Feb 22 '08 #5

P: n/a
On Thu, 21 Feb 2008 15:19:30 -0800 in
b0**********************************...oglegroups.com GTalbot
<ne*******@gtalbot.orgwrote:
On 21 fév, 12:21, "magix" <ma...@asia.comwrote:
>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.
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
st************@mad.scientist.comREMOVE
Currently in Caernarfon, Wales.
Feb 22 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.