I've had this situation happen several times over the past year or so and finally pinned it down. The scenario is as follows:

1) A user creates a node that uses imagefield and uploads a picture
2) A user updates that node at a later date/time and uploads the picture again after making changes to it
3) Imagecache can't find the picture anymore
4) A dump of the node shows that the filepath value is updated with the new file name (typically the file name with _0 at the end) but the filename is still the original file name without the _0

Version information:

Drupal 6.16
CCK 6.x-2.6
Imagefield 6.x-3.2
Imagecache 6.x-2.0-beta10
ImageAPI 6.x-1.6

permissions on tmp and files directory = 777
download method = public

imageapi = GD2

Expected results: User uploads the same file name the filename should be updated to include the appropriate file name (see the value in filepath). The file name is updated by imagefield correctly on the physical file, and the new file name is appended to the filepath attribute - but the filename attribute retains the old file name. The expected result is that filename should have the same value as the filename appended to filepath.

Steps to reproduce:

1) Create a node that has an imagefield
2) Upload a picture
3) Update the node by uploading a new picture with the same file name
4) Dump the node variables and see the differences between filename and filepath
5) Using imagecache you'll get an file not found error

Comments

colinjallen’s picture

This is an issue for me, but I need to resolve it tonight. So in my node template page I called the filepath variable and swapped it with the path to my image cache folder.


//make a variable with the image your working with
$directpath = $node -> field_artwork[0]['filepath'];

//the following code makes a new variable that trades out the URL srting
$mypath = str_replace("sites/default/files/", "/sites/default/files/imagecache/zoom/", "$directpath" );

// and finally, print where needed. 
echo $directpath;


ptitb’s picture

Had the same problem.
Thanks colinjallen for posting your snippet, this worked for me. Although I think this is not the best way to do this.
Like mentioned in some other posts, the old image should be deleted.
But for now this works.

When I used the snippet above I noticed you echo the wrong variable at the end.
It should be $mypath instead of $directpath:

//make a variable with the image your working with
$directpath = $node -> field_artwork[0]['filepath'];

//the following code makes a new variable that trades out the URL srting
$mypath = str_replace("sites/default/files/", "/sites/default/files/imagecache/zoom/", "$directpath" );

// and finally, print where needed.
echo $mypath;
quicksketch’s picture

Category: bug » support
Status: Active » Closed (fixed)

This differentiation between "filename" and "filepath" is a precedent set by Drupal core, ImageField does not have particular control over this behavior. If you need the "true" filename, use basename($item['filepath']).

polmaresma’s picture

Both solutions worked for me, but #3 is the simplest one.
It's a must when you need to print an imagecache of an image that's on a relaten node.

Thank's for your work.