When configuring Ubercart, after adding or changing the image for a product, I get this error:

warning: Invalid argument supplied for foreach() in /home/hofst12sky/public_html/sites/all/modules/filefield/filefield_field.inc on line 127.

Members fund testing for the Drupal project. Drupal Association Learn more


dopry’s picture

Status: Active » Postponed (maintainer needs more info)

can you reproduce with a normal content type with a filefield? imagefield? Is it only on node creation or update? Is there an existing image?

nt2’s picture

Same problem but with standard CCK setup. With an imagefield and on update with no existing image. Does it also on update of other data on a nodes with empty imagefields but only the first time.

zuuperman’s picture

Same here:

Problem is in filefield_field.inc on line 127

// try to delete items from original node
$orig = node_load($node->nid);
// if there are, figure out which ones must go.
foreach($orig->$field['field_name'] as $oitem) {

If there are no images uploaded yet, $orig won't be an array.
Add this code in front of the foreach:
if(!is_array($orig->$field['field_name'])) {

szy’s picture

Status: Postponed (maintainer needs more info) » Fixed
Issue tags: +FileField

@zuuperman, thanks, it works indeed, I had the same problem.


szy’s picture

Title: Invalid argument supplied for foreach() » Invalid argument supplied for foreach() in filefield_field.inc on line 127
cameronp’s picture

Status: Fixed » Needs review

Yep same problem here... just changing status to patch so that they add the fix in..

SeanBannister’s picture

Same problem here

quicksketch’s picture

Status: Needs review » Fixed
1.03 KB

Thanks for nailing this down. I applied the attached fix, which should accomplish the same goal.

quicksketch’s picture

Title: Invalid argument supplied for foreach() in filefield_field.inc on line 127 » Invalid argument supplied for foreach() when updating nodes
cside’s picture

Have applied the patch and the same error message has moved to line 129.

foreach($orig->$field['field_name'] as $oitem) {

quicksketch’s picture

Status: Fixed » Active

Hmm. Does this occur when a node type does or does not have a FileField in it?

kenorb’s picture

kenorb’s picture

I've got the same problem:

warning: Invalid argument supplied for foreach() in /sites/all/modules/contributions/filefield/filefield_field.inc on line 127.

It happen after I've uploaded picture to my content (via imagefield 6.x-3.0-alpha4).
Filefield: "6.x-3.0-alpha7"

It can be related to: #325097: warning: preg_match() expects parameter 2 to be string in common.inc on line 1075 and bootstrap.inc on line 732 errors

quicksketch’s picture

I know it feels like I'm redirecting just about every issue to this patch, but could you try out #397578: Uncouple ImageField from FileField Custom Hooks and see if it corrects the problem? It removes a lot of the funky ImageField/FileField bugs when they're used together. Make sure you have a complete backup of your site (both files and database) before trying it out please.

sammys’s picture

698 bytes

Hi quicksketch,

In any case it would be better to have this part coded defensively. You can avoid the error message by simply adding a cast to an array. A FALSE or NULL will then be converted to an empty array. Here is a patch I just rolled for you that will remove the error message for now and you can concentrate on doing the decoupling.

quicksketch’s picture

Status: Active » Fixed

This should be fixed by #370531: Properly Handle Revisions for document control. Please try out the development version or CVS HEAD to confirm it's really gone. The new segment of code is:

  // Delete items from original node if no new revision was created.
  $orig = node_load($node->nid); 
  // If there are, figure out which ones must go.
  if ($node->revision == 0 && !empty($orig->$field['field_name'])) {
    foreach ($orig->$field['field_name'] as $oitem) {
      if (!in_array($oitem['fid'], $curfids)) {
        // For hook_file_references, remember that this is being deleted.
        $oitem['field_name'] = $field['field_name'];

The !empty($orig->$field['field_name']) check should prevent this error in the case the field doesn't exist at all.

Status: Fixed » Closed (fixed)
Issue tags: -FileField

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