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.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | imagefield-fix-clear-field-session.patch | 769 bytes | jpetso |
| imagefield.module.delete_warning_fixed.patch | 769 bytes | yojoe |
Comments
Comment #1
dopry commentedlooks 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.
Comment #2
yojoe commentedOK, I added the following lines to function imagefield_clear_field_session($fieldname){} in line 315 of the unpatched imagefield.module:
When I upload an image, save the node and return to the node edit-from it outputs the following:
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.
Comment #3
dopry commentedtnx, 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.
Comment #4
ph_j commentedThe same correction should be done in the filefield module ?
Comment #5
(not verified) commentedComment #6
jpetso commentedThe 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.
Comment #7
jpetso commenteddopry 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.
Comment #8
p_palmer commentedJust to clarify, is this how the imagefield_clear_field_session function should look?
Comment #9
jpetso commentedYes, that's exactly how the function should look like.
Comment #10
quicksketchThanks jpesto! Sorry for the horrid response time on such a trivial issue. Committed to 5.x and 5.x--2
Comment #11
jpetso commentedNo prob, thanks for applying!
Note that they spell me differently though - you know, I love pesto, and stuff, remember? :-P
Comment #12
quicksketchDoh! I do that *every* time! I'll try to watch it (again) in the future. Thanks for your contributions to imagefield!
Comment #13
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.