Since I just upgraded to Drupal 5.2 and image 5.x-1.6 (after some problems which I seem to have resolved without knowing how...), every now and then I get the message that derivative images for this or that image have been regenerated. This is normal I think since I have defined some new sizes.
However, each time this happens it seems to be accompanied by this message:

warning: Invalid argument supplied for foreach() in /home/gmpmprdg/public_html/500/includes/file.inc on line 551.

This doesn't seem to stop things working, so I carry on, however...

CommentFileSizeAuthor
#9 image-HEAD.image-file-download.patch642 bytessun

Comments

Robert de Bock’s picture

I have the same problem, let me describe a bit more:
I upgraded from Drupal 5.5 to Drupal 5.6 -and- upgraded the image module from a non-dev version (5.x.1.6) to a dev version (5.x.2.x-dev).
Since these upgrades (could be one or both upgrades combined that caused this error) I can't see images anymore.

Running upgrade.php caused an error that I did not save.

And the errors logged now when viewing images is:
Invalid argument supplied for foreach() in /var/www/virtualhosts/meinit/html/includes/file.inc on line 553.

The log is also filled with regeneration messages like:
Derivative images were regenerated for Image: mypicture.

I will downgrade to 5.x.1.6 now, but am pretty sure I could reproduce this problem. This is the second time this week trying to upgrade the image module.

anarcat’s picture

Status: Active » Needs review

We stumbled upon this issue here after an upgrade from drupal 4.7. There's a simple fix:

--- image.module.orig   2008-05-01 13:55:16.000000000 -0400
+++ image.module        2008-05-01 14:03:49.000000000 -0400
@@ -777,7 +777,9 @@
       if (isset($node->images[$size])) {
         $file = $node->images[$size];
         $headers = image_file_download($file);
-        file_transfer($file, $headers);
+        if ($headers) {
+          file_transfer($file, $headers);
+        }
       }
     }
   }
drewish’s picture

just looking at the patch i'm not sure what this would be solving... you wouldn't be transfering the image so wouldn't that be a bug as well?

anarcat’s picture

I don't think so. If image_file_download() returns false, then there's no image and the code will drop through the "file not found" error, which is fine.

Anyways, image_file_download() should be error-checked before blindly taking what it returns and pass it to another function. In our case, image_file_download() returns -1 so it tells us the image disappeared somehow and we shouldn't try to send it.

jvlagsma’s picture

Version: 5.x-1.6 » 5.x-1.9

Just upgraded to image 5.x-1.9 and the problem still exists. Applied the above solution and it is fine now. Any chance this can be permanently solved in next versions?

drewish’s picture

anarcat, well -1 evaluates to true so i'm not seeing how that would be improved error-checking.

drewish’s picture

Status: Needs review » Needs work
sun’s picture

Please submit a proper patch. See http://drupal.org/patch for details.

sun’s picture

Title: problem in "foreach" » image_file_download tries to transfer non-existing files
Version: 5.x-1.9 » 6.x-1.0-alpha4
Status: Needs work » Needs review
StatusFileSize
new642 bytes

Attached patch implements the same logic as file.inc.

sun’s picture

Status: Needs review » Fixed

Committed to 6.x and 5.x-2.x.

Status: Fixed » Closed (fixed)

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