Hi, when trying to upload a new image using imagefield I get the error above which relates to this part of the code:


/**
 * Validate the widget.
 */
function _imagefield_widget_validate($node, $field, $items) {

  if ($field['required']) {
    // Sum all the items marked for deletion, so we can make sure the end user
    // isn't deleting all of the images.
    $deleted = 0;
    foreach ($items as $item) {
      if ($item['flags']['delete']) {
        ++$deleted;
      }
    }

    if (!count($items)) {
      form_set_error($field['field_name'], t('@field is required. Please upload an image.', array('@field' => $field['widget']['label'])));
    }
    else if (count($items) == $deleted ) {
      form_set_error($field['field_name'],  t('@field is required. Please uncheck at least one delete checkbox or upload another image.', array('@field' => $field['widget']['label'])));
    }
  }
}

And I also figured out that the function _imagefield_widget_validate above was called from the function imagefield_js.

In 90% of the cases I don't get this mistake, but some of the users do get. I tried to replicate it from my home PC and didn't succeed. But I replicated this mistake from my work PC.

Some more details. This mistake does not depend on the browser. I tried with IE6 and FF2 at home - no problem. I tried with the same browsers at work - both fail.

I wonder if this mistake is linked somehow with the VPN/proxy/firewall/other security software installed on my office machine?

I also applied this patch http://drupal.org/node/263637 to add the "minimum resolution" option to the module. Personally, I don't see how it can cause this mistake, but FYI, just in case...

Thank you for your support!

CommentFileSizeAuthor
#10 Picture 1.png26.55 KBjenlampton

Comments

costinius’s picture

Hi, just one more comment on the patch I applied. I didn't apply it automatically as it was created for version 5.x-2.1, but manually, in order to fit it correctly in the new line numbering (for version 5.x-2.4), just by inserting/replacing the corresponding lines of the code where needed.

costinius’s picture

One more update: when I connect my work PC directly to the web, or remotely using VPN, I don't get this mistake. So, the only condition under which this mistake occurs is when I use my PC connected to the corporate network (with all the proxies and other layers between the browser and the web).

So, can anyone help solve this problem? Will downgrading to 2.1 version help? Thanks!

quicksketch’s picture

I'd suggest upgrading to 2.6 that fixed several problems that were in 2.4.

quicksketch’s picture

Status: Active » Fixed

Please reopen if this problem still exists in 2.6.

Status: Fixed » Closed (fixed)

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

jenlampton’s picture

Status: Closed (fixed) » Active

I'm having this problem in 2.6

Invalid argument supplied for foreach() in .../imagefield/imagefield.module on line 859.
jenlampton’s picture

Version: 5.x-2.4 » 5.x-2.6

whoopsie. changing version.

quicksketch’s picture

Thanks jen, any idea how to reliably reproduce this problem?

jenlampton’s picture

Status: Active » Postponed (maintainer needs more info)

that's weird. there's no error now. It's a self-healing module!
let me go back to the client for more details.
Jen

jenlampton’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new26.55 KB

Ok, he's using Windows 7 + IE8. I still can't reproduce the problem on my Mac. Screenshot from his PC attached. (weird, the fieldset is empty. Do you think this could be some kind of IE8 javascript or "security enhancement" problem?)

quicksketch’s picture

This looks like a classic "image is too big problem". In Drupal 5, if ImageField failed because an upload was too large (larger than the server can handle, not larger than ImageField is configured to handle) then the field would just disappear entirely. If an upload exceeds the allowed POST size, then all of $_POST is entirely truncated, possibly causing the foreach() error you're seeing. Try getting the exact file the user is trying to upload and see what size it is. The FileField handbook page on increasing server upload sizes should still apply: http://drupal.org/node/422474

quicksketch’s picture

Status: Active » Closed (won't fix)

Closing out Drupal 5 issues.