I'm creating an HTML form that allows visitors to upload PDF and Word
documents. In HTML, I can create form like the one below that
restricts file uploads to GIF or JPEG files:
<input type="file" name="picture" accept="image/gif, image/jpeg, image/jpg">
This works great. But I want it to restrict it to PDF and Word Doc
files now. What is the code for that? I've tried "application/pdf"
for PDF's but it doesn't seem to work.
I'm aware that this is not something I want to rely on for security
and that support is varied amoung browsers, I just want to make things
easier for my users. Thanks.
xemion-ga |
Request for Question Clarification by
leapinglizard-ga
on
29 Dec 2004 11:18 PST
application/pdf is indeed the MIME type for PDF files, while
application/msword is that for Word files. However, only a limited
selection of MIME types is registered in the typical browser. This is
why, I suspect, your HTML isn't working. Would you be satisfied with a
JavaScript solution instead?
leapinglizard
|
Clarification of Question by
xemion-ga
on
29 Dec 2004 11:25 PST
But even Firefox 1.0 (the newest browser) doesn't support
application/pdf? There's nothing anything else?
How would the javascript function work? Just display an error message
if the user inputs a file that doesn't end with ".pdf" or ".doc"?
|
Request for Question Clarification by
leapinglizard-ga
on
29 Dec 2004 11:42 PST
I honestly don't know which browsers register what MIME types by
default, or how to find this out by any means other than launching
each browser and examining its settings. A JavaScript function would
only be able to assess the type of a file based on its file name, but
I think this is true of your HTML approach as well. Have you tried
misrepresenting the type of a file by changing its name? A JavaScript
function could respond to an unsuitable file name in a number of ways,
such as preventing the upload and raising an alert message.
leapinglizard
|
Clarification of Question by
xemion-ga
on
29 Dec 2004 13:06 PST
I don't think I'm interested in a javascript solution, thanks. I
really just want to keep the user from selecting any non-PDF or
non-Word files from the "select file" box.
|