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;
}
CommentFileSizeAuthor
#1 upload_refresh_filesize.patch813 bytesmaartenvg
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

maartenvg’s picture

Version: 5.1 » 5.x-dev
Status: Active » Needs review
FileSize
813 bytes

This 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.

drumm’s picture

Status: Needs review » Fixed

Committed to 5.x. Already fixed in 6.x.

maartenvg’s picture

Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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