32

By default it can select all type of files,how to restrict it so that it can only select .pdf files?

aksu
  • 5,035
  • 5
  • 21
  • 38
fms
  • 2,067
  • 4
  • 18
  • 16
  • 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 Answers3

77

more explicitly...

<input type="file" accept="application/pdf" /> 
Timmerz
  • 5,746
  • 5
  • 29
  • 44
27

You can use the accept attribute on your form to suggest to the browser to restrict certain types. However, you'll want to re-validate in your server-side code to make sure. Never trust what the client sends you.

David
  • 176,566
  • 33
  • 178
  • 245
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
  • 960,118
  • 257
  • 3,196
  • 2,876