Reviewing Wordpress's media upload functionality, I see that the support the 'accept' attribute which means that native file open browsers can limit what files can be selected, which is really nice:

<input id="p16vjbnqv1168h1n7g1vpb1kk413ff0_html5" style="font-size: 999px; position: absolute; width: 100%; height: 100%; " type="file" accept="image/jpeg,image/png,image/gif,application/pdf,application/msword,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.presentationml.slideshow,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" multiple="multiple">

Since we would have a list of allowed extensions, we should add an API function to convert an array of extensions to an array of attributes, and then do $form['upload']['#attributes']['accept'] = implode(',', $mimetypes);

Files: 
CommentFileSizeAuthor
#8 1632664-file-accept-extensions.patch2.7 KBDave Reid
#2 1632664-file-accept-attributes.patch5.27 KBDave Reid
FAILED: [[SimpleTest]]: [MySQL] 118 pass(es), 2 fail(s), and 0 exception(s). View

Comments

Dave Reid’s picture

Assigned: Unassigned » Dave Reid

Working on a patch today.

Dave Reid’s picture

Assigned: Dave Reid » Unassigned
FileSize
5.27 KB
FAILED: [[SimpleTest]]: [MySQL] 118 pass(es), 2 fail(s), and 0 exception(s). View

Initial patch that I've been working on.

Dave Reid’s picture

Status: Active » Needs review

The last submitted patch, 1632664-file-accept-attributes.patch, failed testing.

Dave Reid’s picture

Assigned: Unassigned » Dave Reid
Issue summary: View changes
Dave Reid’s picture

Dave Reid’s picture

It looks like there is gaining support for just extensions in the accept attribute, instead of mime types, which might help solve some of the compatibility issues I was seeing.

Dave Reid’s picture

Revised patch which uses extensions, still needs tests.

Dave Reid’s picture

I'm almost thinking that this should be a separate module so that it could be used independently of file_entity. Maybe a new file_accept module?

Dave Reid’s picture

Status: Needs work » Closed (won't fix)

I decided this should be available to all without needing file_entity (and this change doesn't require any file entity APIs), so this has been moved to https://www.drupal.org/project/file_accept.