This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Restrict file type in Input type= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Restrict file type in Input type="File"" Watch "Restrict file type in Input type="File"" New topic
Author

Restrict file type in Input type="File"

sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
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


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

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


I love this place!
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
So, server side validation is the only possible way.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

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
 
Consider Paul's rocket mass heater.
 
subject: Restrict file type in Input type="File"
 
Similar Threads
How can i restrict the selecting file type to XML and TXT in file upload..
Problem reading a file
Restricting user to upload a CSV file
File upload
please help a extreme beginner get started?!?