Problem/Motivation
"accepts" attribute allows us to specify file types that can be uploaded via element. This enables some extra client-side validation of uploads and improves UX. Attribute is supported in all major browsers except Safari and IE. Browsers that do not support it will simply allow uploads of all files, which will be handles server-side anyway.
Proposed resolution
Add "#allowed_file_types" option to file and managed_file FAPI elements that will accept allowed file extensions. This will be translated to list of allowed mime types in process callback.
Remaining tasks
Everything ;)
User interface changes
None.
API changes
None. Just adds new functionality.
Original report by @tsphethean
This was originally posted by tsphethean in #625958-106: Support Uploading Multiple Files for HTML5 Browsers via #multiple attribute.
Comments
Comment #2
mbayntonhttp://caniuse.com/#feat=input-file-accept is worth a look. Most notable:
There's no support in iOS Safari (5% market share) and another percent or two from a smattering of other browsers
→ Do we want to also validate by JavaScript? #2235977: JS Client-side file validation is broken (because ajaxPageState is broken?)
Comment #6
AdamPS CreditAttribution: AdamPS commentedFYI
\Drupal::service('file.mime_type.guesser.extension');