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.
To reproduce:
1) Set maximum resolution for images to be uploaded.
2) Attach an image file exceeding the maximum resolution to a node. => drupal will show the file size reflecting the
original resolution. The wrong size information will persist even after submitting the node.
To fix:
Add one line calling clearstatcache in the function _upload_image. This will force the PHP to reread the
file size information after the resize operation. Otherwise, PHP will use the cached (wrong) file size.
function _upload_image($file) {
$info = image_get_info($file->filepath);
if ($info) {
list($width, $height) = explode('x', variable_get('upload_max_resolution', 0));
if ($width && $height) {
$result = image_scale($file->filepath, $file->filepath, $width, $height);
if ($result) {
clearstatcache ();
$file->filesize = filesize($file->filepath);
drupal_set_message(t('The image was resized to fit within the maximum allowed resolution of %resolution pixels.', array('%resolution' => variable_get('upload_max_resolution', 0))));
}
}
}
return $file;
}
Comment | File | Size | Author |
---|---|---|---|
#1 | upload_refresh_filesize.patch | 813 bytes | maartenvg |
Comments
Comment #1
maartenvg CreditAttribution: maartenvg commentedThis bug is still present in current development.
This is a very annoying bug! because if you set a quota of e.g. 1MB and resize all images to some smaller size, users should be able to upload e.g. 40 images that were originally 1MB. Due to this bug they are limited to 1 image, while the true uploaded image-size is less than 1MB.
I've tried your solution, and it works as told. Thanks!
I've attached a patch against 5.x-dev.
Comment #2
drummCommitted to 5.x. Already fixed in 6.x.
Comment #3
maartenvg CreditAttribution: maartenvg commentedThanks!
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.