I always get the following warning message, when I upload an image to a node, save the node (and automatically get redirected to the view-tab) and immediately go back to the 'edit'-tab:

warning: is_file() [function.is-file]: open_basedir restriction in effect. File(/) is not within the allowed path(s): (/tmp:/bin:/usr:/is/htdocs/wp1020583_YAVYCIUQRO) in /is/htdocs/wp1020583_YAVYCIUQRO/www/drupal-5.0/sites/all/modules/cck/imagefield/imagefield.module on line 319.

I tracked the problem down to the imagefield_clear_field_session() function in imagefield.module, the problem is the second (inner) foreach-loop, this one is to much and has to be removed and the first foreach-loop needs to be slightly adjusted:

function imagefield_clear_field_session($fieldname) {
  if (is_array($_SESSION['imagefield'][$fieldname]) && count($_SESSION['imagefield'][$fieldname])) {
    foreach ($_SESSION['imagefield'][$fieldname] as $file) {
      if (is_file($file['filepath'])) {
        file_delete($file['filepath']);
      }
    }
    unset($_SESSION['imagefield'][$fieldname]);
  }
}

I also added the changes as a patch to this post.

Comments

dopry’s picture

Status: Needs review » Needs work

looks like you're passing an empty string to is_file... can you provide a var_dump or print_r of that chunk of the session before and after. If the delta isn't getting into the session, something else is wrong I think.

yojoe’s picture

OK, I added the following lines to function imagefield_clear_field_session($fieldname){} in line 315 of the unpatched imagefield.module:

function imagefield_clear_field_session($fieldname) {
  dpr($_SESSION['imagefield']);
  if (is_array($_SESSION['imagefield'][$fieldname]) && count($_SESSION['imagefield'][$fieldname])) {
    foreach ($_SESSION['imagefield'][$fieldname] as $files) {
      foreach ($files as $delta => $file) {
        if (is_file($file['filepath'])) {
          file_delete($file['filepath']);
        }
      }
    }
    unset($_SESSION['imagefield'][$fieldname]);
    dpr($_SESSION['imagefield']);
  }
}

When I upload an image, save the node and return to the node edit-from it outputs the following:

Array
(
    [field_images] => Array
        (
            [1] => Array
                (
                    [filename] => fue_060.1.gr.jpg
                    [filepath] => /tmp/tmp_YqRrE9
                    [filemime] => image/jpeg
                    [filesize] => 124673
                    [source] => field_images_upload
                    [fid] => upload
                    [preview] => sites/all/files/[type]/[title]/fue_060.1.gr_0.jpg
                )

        )

)


Array
(
)

So you can see, that the delta get's in the session, but you already access it with the first foreach-loop!!! The second foreach-loop is definitely too much, it has to be removed.

dopry’s picture

Status: Needs work » Fixed

tnx, yojoe. Nice fix. I didn't even notice that extra loop. Looks like you finxed some ancillary issues with hanging files in tmp as well.

ph_j’s picture

The same correction should be done in the filefield module ?

Anonymous’s picture

Status: Fixed » Closed (fixed)
jpetso’s picture

Status: Closed (fixed) » Reviewed & tested by the community
StatusFileSize
new769 bytes

The fix got committed incorrectly, in that it drops the $delta => $file loop and still leaves $files as loop variable. In fact, the $delta => $file loop would need to be pushed to the outside loop, so that $delta => $file (or at least, $file alone, but I think it's a good thing to keep $delta for readability) is used instead of $files.

Sounds complicated, but is really easy. Just have a look at the patch.

jpetso’s picture

Version: 5.x-1.x-dev » 5.x-2.x-dev

dopry or quicksketch, please? This patch is tiny and straightforward, and needs to be applied. Do yourself a favor and prevent issues that come up because of this.

p_palmer’s picture

Just to clarify, is this how the imagefield_clear_field_session function should look?

function imagefield_clear_field_session($fieldname) {
  if (is_array($_SESSION['imagefield'][$fieldname]) && count($_SESSION['imagefield'][$fieldname])) {
    foreach ($_SESSION['imagefield'][$fieldname] as $delta => $file) {
      if (is_file($file['filepath'])) {
        file_delete($file['filepath']);
      }
    }
    unset($_SESSION['imagefield'][$fieldname]);
  }
}
jpetso’s picture

Yes, that's exactly how the function should look like.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks jpesto! Sorry for the horrid response time on such a trivial issue. Committed to 5.x and 5.x--2

jpetso’s picture

No prob, thanks for applying!
Note that they spell me differently though - you know, I love pesto, and stuff, remember? :-P

quicksketch’s picture

Doh! I do that *every* time! I'll try to watch it (again) in the future. Thanks for your contributions to imagefield!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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