When you use a <input type="file"> in your application you get the file select dialog box with all files as default.
Is there a way to specify file types for that? Is it possible for example to select “.txt” files only?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is really simple. All you do is add an
acceptattribute that defines what file extensions you’d like to allow.That input would allow only gif and jpegs, but you can allow any comma separated list.
See:
http://www.cs.tut.fi/~jkorpela/forms/file.html#filter
http://www.w3schools.com/tags/att_input_accept.asp
edit: sure, you can do this with javascript too, by checking the filetype after selecting a file, but wouldn’t you rather check before the user selects a file?