English 中文(简体)
Why do the major browsers not support HTMLs ACCEPT attribute for input type="file"?
原标题:

Does anyone know how to use the accept attribute in input tags? I can see it documented, but w3schools indicates that it is not supported by any of the major browsers. Testing also confirms this.

I know that validation should be done server-side, and am doing that now. But it d be nice to have it restrict the types of files in the file upload dialog for usability.

Edit: I am fully aware of the security implications of client-side only validation. I do not intend to remove server-side validation and am looking for a way to improve usability.

最佳回答

The reason why browsers don t actually implement the ACCEPT attribute is that MIME type validation is a science and not just as easy as reading a file extension. Even server-side MIME type verification can be difficult as noted by MediaWiki:

http://www.mediawiki.org/wiki/Manual:Mime_type_detection

Notice they attempt to verify the MIME type even server-side.

问题回答

This attribute is supported by every major browser. Useful links are-- caniuse.com

w3 schools browser support for accept attriute

Thought it would be helpful for someone who wants to know about the browser support of HTML accept attribute.

The most pedantic reason is that it s not required by the HTML4 specification (emphasis mine):

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.

It s an optional feature.

I would personally love to see this. When given image/*, for example, the browser could bring up the user s photo library as the default location and use large icons. text/* could go to the documents folder, etc. Mobile browsers, such as the iPhone, which typically don t allow file uploads at all, could use this to bring up the gallery when the form is expecting an image. We could get crazy and connect to the scanner if desired. The possibilities are endless.

However, this feature is not in common use, and it could be terribly confusing for file upload dialogs to operate differently depending on what the web site supports.

Supporting this tag would mean implementing a way for the browser to determine the MIME type of a local resource, and this would incur a fair amount of heuristics and possible exposure to code injection and/or other vulnerabilities, that browsers already have their fair share of.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签