Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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);
Comment | File | Size | Author |
---|---|---|---|
#8 | 1632664-file-accept-extensions.patch | 2.7 KB | Dave Reid |
#2 | 1632664-file-accept-attributes.patch | 5.27 KB | Dave Reid |
Comments
Comment #1
Dave ReidWorking on a patch today.
Comment #2
Dave ReidInitial patch that I've been working on.
Comment #3
Dave ReidComment #5
Dave ReidComment #6
Dave ReidComment #7
Dave ReidIt 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.
Comment #8
Dave ReidRevised patch which uses extensions, still needs tests.
Comment #9
Dave ReidI'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?
Comment #10
Dave ReidI 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.