Hi,

when running an discogs import from ./node/add/discogs_import, I'm getting this error:

Fatal error: Cannot unset string offsets in /var/www/cinedat/sites/all/modules/image/contrib/image_attach/image_attach.module on line 397

Watchdog log reports various errors like "Could not write to sites/default/files//tmp/R-2826126-1302779862.jpeg".

At ./admin/settings/discogs, the "Discogs image directory": is set to /tmp (not tmp or something relative to /sites/default/files).

Image handler is "Image module's image_attach".

When I change the "Discogs image directory" to tmp, the error logged in watchdog changes to something like: "Could not write to sites/default/files/tmp/R-1969797-1302338621.jpeg"

I don't think that this is a permission issue on my side since I have the "temporary directory" set at ./admin/settings/file-system/settings to /tmp for years without any trouble. However, I'm no expert on *nix permissions (/tmp is "drwxrwxrwt", owned by root:root).

Thx!

Comments

Karlheinz’s picture

Strange. The default in this field should be Drupal's default temp file directory. Did you change it?

Also, I believe you should not include a leading slash. If you're getting two in the Watchdog messages, that may be why you can't write to the directory. I'll have to check my code to make sure.

EDIT: The fatal error message is almost certainly related, even though it originates from the Image module (and not Discography). Again, I'll see if I can replicate the error, look at the code, and report back.

asb’s picture

Thanks for looking into this that fast!

I believe you should not include a leading slash

I tried both ;) Drupal's temporary directory points to /tmp (outside the drupal installation directory). Without a leading slash, it'd point to a directory relative to Drupal's "files" directory. If you're in a jail (shared hosting and the like), /tmp might be mapped to some directory in your home directory; in my case I'm on a dedicated server without a jail (just in case this helps to reproduce the issue).

Edit: I tried to install the 'discogs' module on another site (same server, similar modules, similar configuration), and I do not get this error. Strangely, the settings for 'image_attach' (./admin/settings/image/image_attach), and Drupal's file system (.//admin/settings/file-system) are identical. Even 'image' module is the smae version on both sites (image 6.x-1.1).

The offending line in ./var/www/drupal/sites/all/modules/image/contrib/image_attach/image_attach.module is:

/**
 * Extra submit handler for node forms.
 */
function image_attach_node_form_submit(&$form, &$form_state) {
  // Clear the 0 key in the iids array that arises from selecting the 'None'
  // option. We do this here so image_attach_nodeapi() gets clean data.
  unset($form_state['values']['iids'][0]);
}

I don't understand this :-(

Karlheinz’s picture

You know, this sounds awful familiar... I think it might be a bug with image.module. If I'm right, it was fixed in the DEV version some time ago.

I'm searching it down now, I'll report back shortly.

EDIT: Yup.

See: #768378: Fatal error: Cannot unset string offsets in /modules/image/contrib/image_attach/image_attach.module on line 402 and #747900: warning: array_filter() The first argument should be an array ... image_attach.module on line 349.

This should have been fixed a long time ago. Are you using an old version of image.module? If so, then updating to any version above BETA6 should fix the problem.

asb’s picture

Status: Active » Closed (fixed)

I'm running image 6.x-1.1 (2010-Dec-22), and now went to image 6.x-1.x-dev (2011-May-14), didn't change anything.

Then set "Image handler" at ./admin/settings/discogs to "None"; now nodes are being created, however I'm still getting the errors. Then changed "/tmp" to "tmp" and created a subdirectory "sites/default/files/tmp", which fixes the error messages. I think the issue is solved for me, closing. Please reopen if someone else runs into this as well.

Greetings, -asb

Karlheinz’s picture

Component: Code » User interface
Assigned: Unassigned » Karlheinz
Priority: Normal » Minor
Status: Closed (fixed) » Active

I'm actually going to re-open this, as I think it needs some work.

It sounds like the problem is that you tried to set Discog's temp directory to something outside Drupal's default files directory. This won't work; whatever you put in that field is automatically appended to Drupal's default file directory path. I thought that was clear, but maybe not.

This is by design, since in theory Drupal's files directory should be writable by PHP, but the other directories should not be (for security reasons).

However, the code should at least strip the opening slash off of whatever you put in the field. (I already did this if you put in a trailing slash.) If nothing else, this issue should be left open for that alone.

Also, I have no idea how this would cause the fatal error from image_attach. After you got the temp directory working, did you try re-enabling the images for the Discography type? Did it work, or are you still getting that error?

asb’s picture

There a number of errors when creating 'discogs' nodes, but they're emitted by the 'boost' module; the error I mentioned initially is gone.

Imho, settings for files that start with an slash (/) are not relative to Drupal's default file directory, but absolute paths on the server. They're handeled relative to Drupal's default file directory if the do not start with an slash (the slash is the indicator if the directory is to be handled relative or absolute).

However, I might be wrong with that. The only proof I can give at the moment are the settings on ./admin/settings/file-system/settings which define a temporary directory at /tmp. If this doesn't exist at ./sites/default/files/tmp, Drupal at least doens't complain and works fine. Also, my second site doesn't complain abaout discog's /tmp without having an ./sites/default/files/tmp directory.

Karlheinz’s picture

Imho, settings for files that start with an slash (/) are not relative to Drupal's default file directory, but absolute paths on the server.

I meant, on the Discogs Administration page, e.g. www.example.com/admin/settings/discogs, and not www.example.com/admin/settings/file-system. On the Discogs admin page, it works however I want it to work.

At the moment, whatever you put there is automatically appended to the filepath of Drupal's default file directory (whatever that is). This means that both Drupal's default files directory must be set up, and the folder you enter on the Discogs admin page must already exist. (Or you can leave it blank, and it will be the same as the default files directory.)

Are you saying the forward-slash method you describe, is how I should implement it? I'm actually not sure about that. I think it would be better to leave all of Drupal's files in one place, so you don't even have the option of writing all over the filesystem.

strawberrybrick’s picture

I agree with Karl on this.

Karlheinz’s picture

Status: Active » Closed (won't fix)

Going through old issues. I strongly believe the way it works now, is the way it should work, so I'm marking this issue as "won't fix."