By default it can select all type of files,how to restrict it so that it can only select .pdf
files?
Asked
Active
Viewed 6.5k times
34
-
possible duplicate of [HTML file input field with limited file types?](http://stackoverflow.com/questions/1240934/html-file-input-field-with-limited-file-types) – moinudin Jan 08 '11 at 13:52
-
Client side this is not possible AFAIK. You'll need to check @ server side what exactly the user decided to post. – ChristopheD Jan 08 '11 at 13:52
-
Check also [File input 'accept' attribute - is it useful?](http://stackoverflow.com/questions/181214/) for workarounds. – Emilio Silva Jan 08 '11 at 13:53
3 Answers
80
more explicitly...
<input type="file" accept="application/pdf" />

Timmerz
- 6,090
- 5
- 36
- 49
-
Why is this NOT working when the PC has no Adobe Reader installed? Happened to me today... – Theodore K. May 09 '17 at 13:28
1
Simply put: you can't using the plain html and javascript. The closest you can get is to test the file extension using javascript before submitting the form and show some error message to the user if it is other than .pdf
. You might need to use some client side solution such as Flash upload controls if you want to achieve this.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
-
-
@Šime Vidas, yes indeed javascript could be used to test the extension of the selected file. – Darin Dimitrov Jan 08 '11 at 13:55