472,954 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

<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
Feb 21 '08 #1
5 14353
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Martin Lucas-Smith | last post by:
I am wanting to know whether are XHTML1-valid characters for use within an id attribute and/or a name attribute. ...
5
by: Jonathan Daggar | last post by:
Hello, I'm trying to put together a form with a very tight table formatting. However, every time I put an text-type input field in, the browser pads the area to the right of it with space. I've...
2
by: not 2 swift | last post by:
I thought I would update an old page on which I had used a <INPUT TYPE=image ...> with a <BUTTON><IMG SRC=...></BUTTON> The problem is that <BUTTON> always provides a shadow/emboss effect. Can...
3
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like...
4
by: owen | last post by:
I have an <input> box and i want to disable the apostrophe ( ' ) key, so when you press it, no character appears in the input box. All other keys should work ok. I can trap the keypress event...
10
by: Brian Henry | last post by:
Hi, I am having a problem with an attachment system I made... it works with files up to ~3MB in size then after that if you try to upload a file it just goes to a "Page can not be displayed" page...
4
by: Rick | last post by:
I'm trying to make an input tag visible or hidden based on the value of another input tag, so that when the 1st input tag is changed in anyway, the 2nd input tag will become visible. Thanks in...
2
by: Richard Maher | last post by:
Hi, I'm trying to use the Visibility Style attribute for a Div to effectively PopUp a lightweight window with some additional context-sensitive information, when a user mouses over a given...
1
by: JPhilS | last post by:
Hi to all Webmaster! I have discover this problem when I inserted the scores of the students i a centain subject. I am making a school project with regards to saving students' record. first, I...
1
by: test9991014 | last post by:
Hi folks, I've got something like this: <table> <tr> <td>1</td> <td align=center> <input type=text> </td>
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.