Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restrict file type in Input type="File"

 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to upload txt files to my website.
For that I used <input type="file" accept="txt"> tag in html.

when I click browse option, the file type showing as file *.*

How to restrict the file type only to txt files.

Regards,
Sriram.V
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Check this link, http://www.w3schools.com/tags/att_input_accept.asp, this attribute is not supported by any major browsers and it also gives a tip that any validation should be done server side.

Hope this helps.

Sean
 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, server side validation is the only possible way.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does say it's not properly supported, so it may work, however you should be doing server side validation regardless as it could be possible to circumvent any client side validation.

Sean
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic