How can I have a file upload input filter by file type

I have a form with a file input which I want only PDF files to display when the user clicks browse. How do I do it? Thanks
LVL 4
steveo225Asked:
Who is Participating?
 
b0lsc0ttConnect With a Mentor IT ManagerCommented:
steveo225,

You can't.  The browser doesn't allow that file input to be controlled with script and you can't control which view or type of files are seen in Browse.  You would need to use your own object or applet to provide that type of control.  You can use the (server) script that processes the form and the file to make sure only PDFs are sent and reject it if another file type is sent.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
PhatzerConnect With a Mentor Commented:
According the W3C, there is an 'accept' attribute that can restrict to specific file types, but according to another source, no current browsers support it.

http://www.w3.org/TR/html401/interact/forms.html#adef-accept
0
 
steveo225Author Commented:
Thats what I was wondering. I also found accept but could not figure out how to use it. Thanks to you both
0
 
b0lsc0ttIT ManagerCommented:
Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.

I would avoid using the accept attribute even if it does get support some day.  I doubt it will be universally supported in browsers.  If it is I really hope noone's server script depends on that setting.  The idea is nice but, since it is html, it would be too easy to change or override by a user.  It would defeat the whole purpose of the setting and is probably the reason it won't ever take off.  Those are my thoughts on it at least. :)

Thanks again for a fun question.

bol
0
All Courses

From novice to tech pro — start learning today.