Problem/Motivation

/admin/config/media/file-settings > Maximum upload size field converts everything to bytes, even though I have 5 MB in the field. So, when I try to upload an image in CKeditor field, it says: Files must be less than 5 bytes (instead of 5 MB).

Steps to reproduce

On Drupal 7.83, PHP 7.4, File Entity 2.33, Media CKEditor 2.14

  • /admin/config/media/file-settings > Maximum upload size > Enter any number of MB.
  • Edit/create new node with a CKeditor field. Upload a file (note: via Media Browser provided by Media CKEditor) and notice the description text under "Upload a new file" field. It should have the number entered in the Maximum upload size but instead of MB, it's just the literal number in bytes (not a conversion to bytes).

Proposed resolution

I'm not a programmer, but this post pointed to a clue https://www.drupal.org/project/file_entity/issues/2894662#comment-12167605. In file_entity.pages.inc, line 1276-1281, there's a change for PHP 8 to convert the $max_filesize and $file_entity_max_filesize from string to integer.

- // Cap the upload size according to the system or user defined limit.
- $max_filesize = parse_size(file_upload_max_size());
- $file_entity_max_filesize = parse_size(variable_get('file_entity_max_filesize', ''));
+ // Cap the upload size according to the system or user defined limit. Note: In
+ // PHP 8 file_upload_max_size() returns a string instead of an integer, so
+ // cast it to an integer to avoid a critical error; do the same for the
+ // variable, just in case.
+ $max_filesize = parse_size(intval(file_upload_max_size()));
+ $file_entity_max_filesize = parse_size(intval(variable_get('file_entity_max_filesize', '')));

When I just changed these two lines back to the previous version, the upload maximum went back to 5 MB for me. I know this change was meant for PHP 8, but I wonder should there be another field for a qualifier for the integer entered instead of assuming bytes? Or if it has to be in bytes, then that change should be called out on the update to let users know to manually convert the Maximum upload size into bytes in /admin/config/media/file-settings. This took me a while to figure out it was the File Entity module. I was updating Core and CKEditor and thought those update caused this change.

User interface changes

If it is too much to update the functionality to qualify the integer in the code, then update the help text/language in /admin/config/media/file-settings to say that number entered is in bytes.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vchen created an issue. See original summary.

mikohl’s picture

Status: Active » Needs review
FileSize
1.21 KB

This bug occurs in the File field type using the Media Browser widget as well.

I apologize if I misunderstand why this change was made in the first place, but it appears that this variable is passed to the parse_size core function, which is expecting a string with an optional optional SI or IEC binary unit prefix.

I reverted the change that converted the file_entity_max_filesize variable to an integer, and tested it using phpcs -p file_entity.pages.inc --standard=PHPCompatibility --runtime-set testVersion 8.0, which reported no errors.

I'm pretty new to contributing to Drupal, so please let me know if I'm missing something.

RickJ’s picture

Status: Needs review » Reviewed & tested by the community

I've just hit the same problem. I suggest that this change to file_entity was unnecessary and should be reverted, as in #2.

The actual problem has been fixed in common.inc in #3210215: [PHP 8] Error: TypeError: round() in parse_size function, so no changes in other modules should be necessary.

Installing path #2 fixes the problem for me, and no PHP errors.

  • joseph.olstad committed 4779b13 on 7.x-2.x authored by mikohl
    Issue #3253162 by mikohl, vchen, RickJ: File Settings: Maximum upload...

  • joseph.olstad committed 458dfb3 on 7.x-3.x authored by mikohl
    Issue #3253162 by mikohl, vchen, RickJ: File Settings: Maximum upload...
joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed
omarsidd’s picture

Appreciate the fix, came here because we just hit this bug.
But the frequency of bugs in a module used by 160K sites at present is concerning... Coding standard improvements aren't improvements if they break basic functionality. It's far far better for devs to test and release slowly, rather than 160,000 admin teams try to figure it out individually. Thanks...

joseph.olstad’s picture

@omarsidd on the bright side, we've added php 7.4, php 8.0 and php 8.1 compatibility.

Status: Fixed » Closed (fixed)

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