File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Restricting access to file types in file input tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Restricting access to file types in file input tag" Watch "Restricting access to file types in file input tag" New topic
Author

Restricting access to file types in file input tag

Ramesh Etta
Ranch Hand

Joined: Sep 18, 2007
Posts: 46
Hi,

I got a problem like i write a input file element like this

<input type="file" name="testfile" >

When i execute this i get a text box with browse. when i click browse i am able to see all files. is there any way to restrict file types like,i want to select only xml files to be uploaded.

and i want to display some message if i select some other file type rather that xml files (client side validation).

I am using jsp and html.

please help me.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can do a validation on the field before you submit, but you can not restrict the file contorl itself.

Eric
Ramesh Etta
Ranch Hand

Joined: Sep 18, 2007
Posts: 46
can you send me code validating this?
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
http://www.w3.org/TR/html4/interact/forms.html#adef-accept says -

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").




So, maybe one day...
[ October 27, 2007: Message edited by: Dan Drillich ]

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Restricting access to file types in file input tag