HTML Forms, file input. How extensible is it?

M

Mongoose

Hi all,
We use
<input type="file" name="FILEFILENAME" value="">
to get file input dialogs. My questions are:

(1) Is it possible to add a bunch of file filters to the opening dialog
box? (*.txt, *.doc, etc etc)

(2) Is it possible to get the type of file selected in the dialog?
Meaning the index of the element if (1) is possible, so that you could
mess around with it in the java script.

If both the above are not possible... is anyone at the W3C thinking
about adding this neat feature into the HTML spec in the near future?
Anyone? :)

Thanks!
 
B

Benjamin Niemann

Mongoose said:
Hi all,
We use
<input type="file" name="FILEFILENAME" value="">
to get file input dialogs. My questions are:

(1) Is it possible to add a bunch of file filters to the opening dialog
box? (*.txt, *.doc, etc etc)

There is the 'accept' attribute for the INPUT element which takes a list of
MIME types (not file suffixes). Don't know if this is handled by any
browser.
(2) Is it possible to get the type of file selected in the dialog?
Meaning the index of the element if (1) is possible, so that you could
mess around with it in the java script.

No.
You could look at the selected filename (in fact it could be a list of
filenames, but most browsers do not support selecting multiple files...) at
see, if it has a known suffix. But keep in mind that the connection between
filetype and suffix is pretty arbitrary and that there are operating
systems that do not use this concept at all.
The only reliable way to determine the filetype is by looking at the file
contents, e.g. using the UNIX 'file' tool. And you have to do this on the
server side of course.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top