473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 14390
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.