Problem/Motivation
It is not possible to upload files with an uppercase file extension (e.g. 'image.PNG') via media_directories_ui.
media_directories_ui checks the File Type via its extension. It does so case insensitive. Possible file extensions from Drupal Media (e.g. field.field.media.image.field_media_image. -> file_extensions) are always stored lowercase, it is not possible to add a uppercase variant to the allowed file extensions.
File upload in Media-Module (/media/add) compares case insensitive, uploading an uppercase-extension is possible. The behaviour of media_directories_ui deviates from media.
Steps to reproduce
1. Go to admin/content/browser, click 'Add Media'
2. Upload a file with an uppercase or mixedcase file extension, e.g. 'image.PNG'
3. The Upload-Modal returns the error Messsage
The specified file Firefox.PNG could not be uploaded.
- Only files with the following extensions are allowed: %files-allowed.
Proposed resolution
In media_directories/modules/media_directories_ui/src/MediaDirectoriesUiHelper.php, replace line 77
if (in_array($extension, explode(' ', $field_config->getSetting('file_extensions')))) {
with either
if (preg_match("/(^|\s)$extension(\s|$)/i", $field_config->getSetting('file_extensions'))===1) {
or (if you prefer a non-regex-approach)
if (in_array(strtolower($extension), explode(' ', strtolower($field_config->getSetting('file_extensions'))))) {
Issue fork media_directories-3535402
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mullzk commentedComment #3
ytsurkThx for your contribution.
I would prefer the non-regex approach and will commit that when I find time.
Comment #6
d.steindl commentedI've changed the case-insensitive check to use strtolower instead of a regex & created a merge request. Please review :)
Comment #7
mullzk commentedThanks d.steindl. Your MR solves my problem
- Testing with 2.2.0-beta1 -> Upload of "testfile.PNG" fails with above error-message
- Testing with dev-3535402-fix-uppercase-file-extension -> Upload works as expected.
Moving to rtbc
Comment #8
mullzk commentedComment #10
rang501 commentedLooks good to me, merged into 2.2.x