Current the list of allowed extensions on file/add/upload are the more restricted set allowed by file_save_upload(). We should alter in the media__file_extensions variable.

#8 media-upload-problem.jpg264.47 KBbensnyder


Dave Reid’s picture

I think just doing this might be the trick:

 * Implements hook_menu_alter().
function media_menu_alter(&$items) {
  // Add the more permissive list of allowed file extensions to the file/add
  // upload form.
  $items['file/add']['page arguments'][1] = array(
    'file_extensions' => media_variable_get('file_extensions'),

Not sure about this vs using a form_alter though.

Dave Reid’s picture

Looking at, it appears we also lost support for media_variable_get('max_filesize') as well.

Dave Reid’s picture

Title: Media allowed extensions not used on file/add/upload » Media allowed file size not used on file/add/upload

This is now fixed for the extension list with in 7.x-2.x.

Thomas Factory’s picture

file/add/upload in 7.x-2.0-unstable5+1-dev still does not match the allowed file extensions from the media browser settings and is only allowing file extensions from file_save_upload().

Dave Reid’s picture

Make sure to update both Media and File entity to their latest versions.

Thomas Factory’s picture

Okay, I changed File entity from 7.x-2.0-unstable5 to 7.x-2.x-dev.

Under the upload form file/add I still get "Files must be less than 8 MB. Allowed file types: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp."

Now, the files for a single or a multiple uplodad can be selected and they appear in the upload form. When I click Start upload the upload is indicated with the green upload bar. After the upload seems to be completed, I get the message "Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp." –– And the files aren’t uploded.

bensnyder’s picture

I can upload images from a wysiwyg and an image field with media widget, but I cant upload from /file/add. Using latest file_entity and media 2.x devs.

Warning: filesize(): stat failed for public://tulips.jpg in file_save() (line 570 of /var/www/[site]/includes/
bensnyder’s picture

264.47 KB

Dave -- I'm checking apache error logs and drupal's logs but can't find the root of the problem. Do you have any suggestions for testing this? I can't upload anything from file/add.

It's supposed to be adding the image to /sites/default/files/media but it's uploading to /sites/default/files/. Odd...

Media Upload Problem

bensnyder’s picture

Also, the file never actually gets uploaded.

Dave Reid’s picture

@bensnyder: Did you actually hit 'Submit' on that form after upload? Also, uploading on file/add will only upload to your site's root file directory since you're not uploading as a field which has a configured upload sub-directory.

bensnyder’s picture

Dave -- lol yes I hit submit :)

Here's some new stuff from the event logger:

LOCATION	http://[site]/file/ajax/upload/form-P6FHX3QMI-6fOgcUDczumNxAf_U3B4mbF49-0Kr0woQ
REFERRER	http://[site]/file/add
MESSAGE	The file permissions could not be set on public://lighthouse.jpg.

LOCATION	http://[site]/file/ajax/upload/form-P6FHX3QMI-6fOgcUDczumNxAf_U3B4mbF49-0Kr0woQ
REFERRER	http://[site]/file/add
MESSAGE	Warning: filesize(): stat failed for public://lighthouse.jpg in file_save() (line 570 of /var/www/[site]/includes/
SEVERITY	warning

LOCATION	http://[site]/file/add
REFERRER	http://[site]/file/add
MESSAGE	Notice: Undefined property: stdClass::$image_dimensions in file_entity_file_update() (line 63 of /var/www/[site]/sites/all/modules/file_entity/
bensnyder’s picture

Here is the contents of http://[site]/file/ajax/upload/form-P6FHX3QMI-6fOgcUDczumNxAf_U3B4mbF49-0Kr0woQ:

[{"command":"settings","settings":{"basePath":"\/","pathPrefix":"","ajaxPageState":{"theme":"ytdc","theme_token":"M18j0oKfiZDVhFSfkzK6YcM096KJAzOEcX2d6QlDCPw"},"colorbox":{"opacity":"0.85","current":"{current} of {total}","previous":"\u00ab Prev","next":"Next \u00bb","close":"Close","maxWidth":"100%","maxHeight":"100%","fixed":true,"__drupal_alter_by_ref":["default"]},"googleAnalyticsReportsAjaxUrl":"\/google-analytics-reports\/ajax","shadowbox":{"animate":1,"animateFade":1,"animSequence":"wh","auto_enable_all_images":0,
"slideshowDelay":"0","viewportPadding":20,"useSizzle":1}},"merge":true},{"command":"insert","method":"replaceWith","selector":null,"data":"\u003Cdiv class=\u0022messages error\u0022\u003E\n\u003Ch2 class=\u0022element-invisible\u0022\u003EError message\u003C\/h2\u003E\nAn unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (100 MB) that this server supports.\u003C\/div\u003E\n","settings":null}]
Dave Reid’s picture

Hrm, I'm thinking that the server permissions are not properly set on your public files directory, ensuring that the web server can actually write to it, if drupal_chmod() is failing (which is where that error comes from). I think we need to move this to a separate issue since the problem isn't actually that we can't upload files, it's that permissions aren't set correctly, which is unrelated to being able to use this form.

bensnyder’s picture

Dave - thanks for the reply. It can't be file system permissions... I know for sure I have that set correctly. I'm doing more digging tonight - I'll post back my findings. Thanks!

bensnyder’s picture

Finally found a [temporary] fix!

Thoughts, anyone?

acbramley’s picture

A similar form_alter hook is required for the file_entity_add_upload_multiple as well, see

gmclelland’s picture

  • Dave Reid committed 2666215 on 7.x-3.x
    Issue #1600610: Fixed media allowed extensions not used on file/add/...
joseph.olstad’s picture

Issue summary: View changes
Status: Active » Fixed

Fixed, and issues marked as related have been fixed.

Thanks to @Dave Reid , and others.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.