Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

HTML <input type="file"> accept attribute

What purpose does it serve during file upload?

9:00 pm on Oct 3, 2003 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

There was a discussion started at the tail end of this PHP forum thread regarding file uploads [webmasterworld.com] and it started drifting into more of an HTML topic rather than server-side processing.

What purpose does the accept attribute serve during a file upload? For example:

<input name="userfile" type="file" accept="application/pdf" />

The best I can figure so far is that user agents may use this to filter out non-conforming files. Yeah, right. Try it once. I tested IE6.1 and NN7.1 and either one will allow me to select anything I want, not just a .pdf file. Which is fine, I run lots of editing on the server side anyway.

OK, then is it a server-side parameter? Seems Macromedia CF does something with it. This is what I've found so far:


There is no functionality implemented for this property unless defined by the author.



Controlling the type of file uploaded

For some applications, you might want to restrict the type of file that is uploaded. For example, you might not want to accept graphic files in a document library.

You use the accept attribute to restrict the type of file that you allow in an upload. When an accept qualifier is present, the uploaded file's MIME content type must match the criteria specified or an error occurs. The accept attribute takes a comma-separated list of MIME data names, optionally with wildcards.

A file's MIME type is determined by the browser. Common types, like image/gif and text/plain, are registered in your browser.


Not all browsers support MIME type associations.


Looks like it is used moreso on the server-side as opposed to being something to use or rely on in the user agent. If anybody has broader knowledge of the accept attribute, by all means enlighten us!
9:20 pm on Oct 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
votes: 0

The REC says...

accept = content-type-list [CI]
This attribute specifies a comma-separated list of content types that a server processing this form will handle correctly. User agents may use this information to filter out non-conforming files when prompting a user to select files to be sent to the server (cf. the INPUT element when type="file").

Mabye they mean they made is so user agents could do that but none actually do, heh. ;)

Or mabye it is used to set the filter mask for the file dialog (i.e., the "All files (*.*)" part) or something like that...just guessing...never even know about it before just now.


[edit:] I just tried this:

<input name="userfile" type="file"
accept="<?php echo $_SERVER['HTTP_ACCEPT'];?>" />

And it gave me a nice big comma-separated list, but Firebird 0.6.1, Opera 7 and IE 6 just had *.* as the default mask in the dialog, heh. [/edit]