HTML file form, accept Word documents

I have a slightly strange problem here. (Either that, or I'll just miss something stupid.)

I have a form for uploading files, and I want it to accept only certain types of files, including MS Word documents. I added the MIME types .doc and .docx ( application/mswordand application/vnd.openxmlformats-officedocument.wordprocessingml.documentrespectively) to the accept attribute of the file input field, but when I click "select file", the .doc and .docx files still remain gray as they are not allowed to upload.

So what am I missing? Any help or pointers would be greatly appreciated!

(And yes, I know that form validation is not a good way to filter downloaded files. I have PHP that is more convenient for the user, so they do not go and the forbidden file does not load.)

+3
source share
2 answers

I am a MIME type for Word files, probably not registered in the browser, so the Word file is reported as application/octet-stream. In general, filtering MIME types in HTML forms does not work reliably, with the exception of the common MIME types of images.

You can create a JavaScript solution to check the file extension.

0
source

Attribute support acceptwas poor, but gradually becoming more common. In my Google Chrome 19, the element <input type="file" accept="application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword" />works so that the selection is limited to .doc and .docx files. Other browsers usually ignore this attribute accept, although, for example, Firefox supports some simple cases, such as accept="image/gif".

MIME ( ) -. , , , .

+4

All Articles