html - Can I safely use a list of extensions (not mimetypes) in the input accept attribute -
so want limit users options upload list of specific file extensions. purely create easier user, limiting filetype upload on server also.
i have list of extensions not list of mime types. accepted extensions can potentially change, , don't see reliable way dynamically calculate mime types(and rather avoid this); instead feed extensions 'accept' attribute of <input type="file"> element.
i have noticed works intended on chrome, not in ff or ie10 (in these browsers seems fallback files).
i realise isn't part of standard there way take extensions instead of mimetypes in 'accept' attribute (modern browser) cross-browser friendly. test case used <input type="file" accept=".doc,.docx,.bad" />
if not possible, best approach? note: have no garuntee servers registry contain mimetypes of extensions use, , because list can long rather impractical (and lastly resort) manually maintain list date of mimetypes.
no, not safe. html 4.01 accept attribute defined value comma-separated list of media types. has been implemented relatively (e.g., no back upwards in ie 9).
in html5 drafts, attribute has (recently) been extended allow extensions well, , html5 cr description of file input recommends: “authors encouraged specify both mime types , corresponding extensions when looking info in specific format.” however, has not been implemented yet.
it conceptually messy. media types design meant standardized , interoperative way of specifying types of files , other data. filename extensions parts of filenames treated in special ways in systems, no standards, beyond mutual practices aren’t consistent. mixing 2 calls trouble, though there pragmatic reasons behind this.
in case, in file input, mapping between filename extensions , media types performed browser underlying operating , file scheme of user’s computer; server not involved.
using file api, could, on browsers supporting (e.g., firefox) check out filename(s) of selected file(s) , pick filename extension(s) , inform user if selected file(s) won’t accepted. happen after selection, without affecting file selection widget, , inquire user alter choice.
html html5 file-upload
No comments:
Post a Comment