I have set the filefield's file size limit to well above what is needed, but continue to get this error message when trying to upload a file:

The specified example.zip could not be uploaded. The file is 36.78 MB exceeding the maximum file size of 32 MB.

32MB is the php.ini setting. My filefield setting is 5000 MB. Cache was flushed after setting the new limit. On the content creation form the files size limit info still says "Files must be less than 32 MB" as well.

CommentFileSizeAuthor
#6 uploaded-file.png12.8 KBwuffers
#6 file_field_settings.png14.83 KBwuffers

Comments

omd’s picture

One addendum, it seems the super user can upload files without the error message, but any other user is getting the error message. And to clarify it seems to be observing the post max size.

omd’s picture

Can get the module to work if I hack Drupal core:

I made changes to includes/file.inc (found on https://api.drupal.org/api/drupal/includes!file.inc/function/file_valida...):

Changed line 1712 from:
if ($user->uid != 1) {

to:

if ($user->uid = 0) {

This basically bypasses the file size validation check:

// Bypass validation for uid = 1.
if ($user->uid != 1) {
if ($file_limit && $file->filesize > $file_limit) {
$errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));
}

Mixologic’s picture

Setting filefield to 5000MB *does not* override the php_ini setting of 32MB. That is a hard limit set by php, and cannot be overridden by drupal at runtime.

If would like to be able to upload larger files, change the setting in php.ini. See this S.O. post for more info: http://stackoverflow.com/questions/2184513/php-change-the-maximum-upload...

omd’s picture

That is the whole point of this module and Plupload Intergration module - allowing large file uploads, larger than php limits. No?

Mixologic’s picture

You're right, I jumped the gun there - I thought this was the filefield queue - I didnt see it was part of the FileField Sources Plupload project.

I poked around in it and it appears as though this module doesn't actually do anything for larger file upload. It just allows the setting to be set higher, but it doesnt actually manipulate the filefield upload validators, which *are* constrained by the php.ini settings.

In order for this to actually work, it would need to manipulate the filefield upload validators and actually remove that file_validate_size check.

wuffers’s picture

StatusFileSize
new14.83 KB
new12.8 KB

From my understanding, that's the whole point of the Plupload library and these Drupal integration modules - to have large file uploads without having to change php.ini settings. In a shared environment it's not feasible to set post_max_size to something like 2G (besides, I'm not sure it would work either, as you'd have to most likely change max_execution_time as well to handle that amount of data). Incidentally, the Plupload integration module (plupload.module) has on line 321:

'chunk_size' => parse_size(ini_get('post_max_size')) . 'b',

which, contrary to its documentation uses a chunk size of post_max_size instead of 1M chunks. Putting in a 2G value will mostly be asking for trouble.

I replicated this in a clean Drupal 7.23 install, with just File Field sources, FileField Sources Plupload 7.x.1.1 and Plupload 7.x.1.3, with Plupload 1.5.7 library.

php.ini has these settings:

post_max_size = 8M
memory_limit = 128M
upload_max_filesize = 2M

As noted above, as the super user (uid=1), you can upload anything past the file limit of 2M (up to the limit set in the file field setting), even though it says "File limit is 2 MB"), so what #3 says is not correct. You can even see in the screenshot that my file is bigger than the post_max_size of 8M.
uploaded-file

The file field in that content type has 500 MB set as its limit, and I've used the Plupload widget instead of the default upload one (this has the advantage of doing file size validation before upload occurs, unlike the default file upload widget).

field_field_settings

Obviously editing Drupal core's file_validate_size function isn't ideal, and looking at the function :

function file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0) {
  global $user;

  $errors = array();

  // Bypass validation for uid  = 1.
  if ($user->uid != 1) {
    if ($file_limit && $file->filesize > $file_limit) {
      $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));
    }

    // Save a query by only calling file_space_used() when a limit is provided.
    if ($user_limit && (file_space_used($user->uid) + $file->filesize) > $user_limit) {
      $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));
    }
  }
  return $errors;
}

Even though the file field setting says "Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP's maximum post and file upload sizes (current limit 2 MB)." and it is overridden, the "maxsize" is only using the php.ini (it seems to be taking either post_max_size or upload_max_filesize setting, whichever is smaller). Shouldn't "maxsize" be taken from the file field setting, and checked against that setting?

I don't understand enough of how all 3 modules work together and if it is possible at all to pass the maxsize setting from one of those modules for the file_validate_size function, but that seems to me the way to do it.

The hack outlined in #2 works, and using the Plupload upload widget does have file size validation, but I wonder what else breaks because it essentially bypasses any type of file size validation when we're not a super user.

wuffers’s picture

Oops, didn't see your reply in #5 before I started mine.

[snip] I poked around in it and it appears as though this module doesn't actually do anything for larger file upload. It just allows the setting to be set higher, but it doesnt actually manipulate the filefield upload validators, which *are* constrained by the php.ini settings.

In order for this to actually work, it would need to manipulate the filefield upload validators and actually remove that file_validate_size check.

.. and hence why OP's #2 hack in Drupal's core includes/file.inc does work. I'm just surprised that I can't see an issue for this already dealt with (either in core or one of the contributing modules) with the age of these integration modules and the amount of people using them.

wuffers’s picture

Delete/comment out these 3 lines instead

if ($file_limit && $file->filesize > $file_limit) {
      $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));
    }

uid 0 is the anonymous user and it was matching on some conditions.

rbennion’s picture

Same issue for me. User 1 bypasses global file size check. Any other user is restricted to global max as indicated in PHP.INI.

xpersonas’s picture

Issue summary: View changes

Subscribing...

acouch’s picture

I was able to get around this without hacking core by

  1. unsetting the ['#upload_validators']['file_validate_size'] in hook_field_widget_form_alter().
  2. Adding a higher value to the Maximum upload size setting in the file field

Not very elegant, don't have time currently for a better solution.

TWD’s picture

acouch

Could you post your code?
I have the same problem with adding image files into a body field via the Wysiwyg.

acouch’s picture

/**
 * Implements hook_field_widget_form_alter().
 */
function MY_MODULE_field_widget_form_alter(&$element, &$form_state, $context) {
  if (isset($element[0]['#field_name']) && $element[0]['#field_name'] == 'field_upload') {
    // Remove the file size limit set in php.ini.
    unset($element[0]['#upload_validators']['file_validate_size']);
    // For some reason with the plupload file source we get a doubling of the
    // description.
    $element[0]['#description'] = '';
  }
}
TWD’s picture

Thank you so much!

One more question though.

Would this code be the same for both images uploaded to a dedicated image field
AND images uploaded and embedded into a free form area like a "body" field?

I assume it would since target is the Media Module file upload widget?

TWD’s picture

Subscribing

socialform’s picture

All of these solutions seem like temprary fixes but this has been an issue for years. It makes me wonder if everyone is having this issue or just a few. Are there people uploading large files without having this issue?

On the project page it lists as a "Core Feature": Maximum file size can be set larger than PHP limits. It clearly doesn't do this.

Can the maintainer correct the project page or provide a solution? Thanks to anyone who can shed light.

bwaindwain’s picture

I think the key word is "can". PHP and Drupal have file handling limits and this module doesn't override them. But, with this module AND some clever coding like #13 or my comment over at issue 2229693, it can be done.

Maybe this should be more clear in the module's description page.