Google Answers Logo
View Question
 
Q: HTML Input File Accept Field ( No Answer,   1 Comment )
Question  
Subject: HTML Input File Accept Field
Category: Computers > Programming
Asked by: xemion-ga
List Price: $10.00
Posted: 29 Dec 2004 11:10 PST
Expires: 05 Feb 2005 16:42 PST
Question ID: 448809
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.
Answer  
There is no answer at this time.

Comments  
Subject: Re: HTML Input File Accept Field
From: rbanyal-ga on 06 Jan 2005 16:51 PST
 
I tried your code in MSIE6 and FireFox. I don't see any difference and
I still see the default file types.

Here's what I tried:

<HTML>
<HEAD>
<TITLE> test file types </TITLE>
</HEAD>

<BODY>
<input type="file" name="picture" accept="image/gif, image/jpeg, image/jpg">
</BODY>
</HTML>

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy