Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restricting access to file types in file input tag

 
Ramesh Etta
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you send me code validating this?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic