is there any way that html element file
only accept PDF files and when we
To get the HTML file input form element to only accept PDFs, you can use the accept attribute in modern browsers such as Firefox 9+, Chrome 16+, Opera 11+ and IE10+ like such:
You can string together multiple mime types with a comma.
The following string will accept JPG, PNG, GIF, PDF, and EPS files:
In older browsers the native OS file dialog cannot be restricted – you'd have to use Flash or a Java applet or something like that to handle the file transfer.
And of course it goes without saying that this doesn't do anything to verify the validity of the file type. You'll do that on the server-side once the file has uploaded.
A little update – with javascript and the FileReader API you could do more validation client-side before uploading huge files to your server and checking them again.