Hi there. I am using this great module because it is so convenient to be able to just attach images and have them transformed into image nodes on the fly. These can then be themed automatically, which makes it easy for the end user.

However, I am seeing an idiosyncrasy of the module: as the image files are changed into nodes, they are moved to the images subdirectory. But the upload module continues to show them as inhabiting the files main directory.

I am putting this is as a support request and not a bug, but I would like to know what you think is the best way of solving this problem.

See attached screenshot. Thanks!

CommentFileSizeAuthor
filename_incongruency.png27.38 KBvictorkane

Comments

ansorg’s picture

Category: support » bug

change to "bug".

It's not only cosmetic, it causes other modules that work with the image to fail because the image cannot be found at the stored filename "sites/domain/files/mage.jpg"

I looked at the code but so far no idea how to fix this :(

ansorg’s picture

hm, I might have an idea what's going wrong:

first, I use http://drupal.org/project/uploadpath module in addition. This has some issues of it's own but I got it to behave as it should. So, when I attach an image to a node

- uploadpath kicks in and copies the image into a specified subdirectory "sites/domain/files/newfolder/*.jpg" and updates the files table

- upload_image kicks in and creates a image node out of that $file from the files table. The physical files remain untouched in the "newfolder" (checked this by commenting out the _image_build_derivatives call from the module)

But at some point - either directly in the module (if not commented out) or later, if the images are actually displayed, the _image_build_derivatives (from image.module) gets called and this function seems to move/create all images in "sites/domain/images", ignoring the current file location.

To me it looks like this has to get changed?

Could anybody take a look at all this and confirm my findings?

Since I believe this is an issue in image.module I post the bug over there: http://drupal.org/node/256210

Jens

acolonna’s picture

A simple solution is to add this code to the upload_image_save function:

if ($node->type == 'image') {
    /*
      Update the filepath for the file to the location of the images created by Image (otherwise the original attachment file is used instead, which is inconsistent)
    */
    $file_info = pathinfo($node->images[IMAGE_ORIGINAL]);
    $node->file = $node->images[IMAGE_ORIGINAL];
    $node->image->filename = $file_info['basename'];
    $node->image->filepath = $node->images[IMAGE_ORIGINAL];
    $node->image->description = $file_info['basename'];
    db_query("UPDATE {files} SET filename = \"%s\", filepath = \"%s\" WHERE fid = %d", $file_info['basename'], $node->images[IMAGE_ORIGINAL], $node->image->fid);
}
killes@www.drop.org’s picture

Hobbes-2’s picture

subscribe