Hi,

This is a quirky situation whereby an image is uploaded, say with the name image77.jpg. If that image is then deleted and a new image uploaded with the exact same name but quite a different image, then while the full page version of the image is correct, thumbnails aren't.

This originally occured in version 5.1 so I upgraded but it is still occurring. I have the following in mymodule_nodeapi()

case 'delete':
if($node->type=="image") {
imagecache_preset_flush('thumbnail_preset');
}

I thought this might get rid of any rogue thumbnails, but still I keep getting the thumbnail for the deleted image appearing.

This may well be a problem with the upload module or file.inc but I thought I'd see if anyone else has experienced anything like this.

Comments

apratt’s picture

Running into the same problem...

I suspect this is a similar issue #356429: empty IMG tags shown in views where image field is empty just at an earlier stage of diagnosis

I suspect I need to peek into the database to figure out what is happening.

NewZeal’s picture

I eventually did this in mymodule_nodeapi $op = 'update', which solved the problem:

		  $real_path = db_result(db_query("SELECT f.filepath FROM {files} f LEFT JOIN {content_type_image} i ON f.fid=i.field_image_image_fid WHERE i.nid=%d", $node->nid));
		  imagecache_image_flush($real_path);
danny_joris’s picture

I have the same problem. Deleting old and uploading new original images is no problem, but the images in imagecache/ stay the same. It should be really basic thing to delete or update images in the imagecache folders, right? I haven't tried the above snippet yet, but i feel that i should not be playing around with code snippets for a function that is so standard.

Does anyone have an idea why this happens?

I use the latest version by the way: 6.x-2.0-beta9.

mfb’s picture

Version: 5.x-2.3 » 6.x-2.x-dev

Subscribing

OnlineWD™’s picture

I think the problem is ajax, deleting the image and then pressing save is a working process but deleting an image and reuploading the same image or at least image with same file name prevents imagecache image being deleted. This needs to work for making revisions. It's a real headache for webmasters too. I get unknown action when I try to flush cache afterwards and cache is not flushed. I have to go in and manually remove the cache folder before things work properly again. Thanks ..

OnlineWD™’s picture

Is a fix for this being considered? It causes havok for my site sometimes and yet when I delete all files in image cache every thing works fine again. Why not simply flush the entire cache every time content is deleted if content contains imagefield?

j0rd’s picture

Title: When uploading new image of previously deleted image with the same name, new thumbnail is not created » When uploading new image of previously deleted image with the same name, the old thumbnail is displayed.
Priority: Normal » Critical

I'm having the same issue, which is causing my ubercart install to display the wrong product images.

Here's how you can replicate this bug:

1. Create a node which has a cck imagefield in it. Upload test.jpg and save the node.
2. Visit the node page so that the imagecache thumb is produced.
3. Delete the node.
4. Create another node and upload test.jpg.
5. Visit this new nodes page and you'll notice a stale imagecache thumb.

Here's another way you can replicate this bug:

1. Create a node which has a cck imagefield in it. Upload test.jpg and save the node.
2. Visit the node page so that the imagecache thumb is produced.
3. Remove the image associated with the imagefield and save the node.
4. Edit the same node again, and upload a different picture called test.jpg and save the node.
5. Visit this new nodes page and you'll notice a stale imagecache thumb.

Here's a way you CAN NOT replicate this bug:

1. Create a node which has a cck imagefield in it. Upload test.jpg and save the node.
2. Visit the node page so that the imagecache thumb is produced.
3. Remove the image associated with the imagefield and re-upload another image with the same name.
4. Save the node.
5. Visit this new nodes page and you'll notice that the imagecache is updated. This is because imagefield will re-name the second image uploaded to test_0.jpg thus making it a new name for the image/imagecache.

Solutions for this:

Imagecache will need to delete the cache files it creates when an image is updated or deleted. I would assume this could be done by implementing hook_nodeapi. Otherwise it will have to implement a different storage system based off FID instead of filename.

I consider this a fairly critical bug with imagecache, although most users will never notice it as it would happen rarely. But I'm sure if it was easier to come across, more people would be complaining.

OnlineWD™’s picture

I'm not sure but I think after setting imagefield_thumbs folder to 777 and flushing cache my problems have gone. Not 100% sure though, need to test it some more.

j0rd’s picture

Flushing your cache will solve the problem.

But we can't tell the end users (and perhaps they wont have permissions) to flush their imagecache every time they upload a new image. This isn't practical and there is a bug which causes this problem which should be resolved. It's also a huge burden resource wise as each imagecache thumb will need to be re-created.

premanup’s picture

I'm using imagecache fairly long time and now described issue happend on my site. There are about a few thousands of imagecached images. So I can't just flush it all.

premanup’s picture

This small bash-script has helped me to delete all imagecached files which has no source at the time. I guess it can be used by cron to prevent risk of wrong image show.

find files/imagecache/thumb/i -type f -printf '%f\n' | while read link; do [ -e "files/i/$link" ] || rm "files/imagecache/thumb/i/$link"; done

Here:
files/i - source directory
files/imagecache/thumb/i - imagecache directory

kanani’s picture

Subscribing my scenario is second one in #7 except name of image is irrelevant

Here's another way you can replicate this bug:

1. Create a node which has a cck imagefield in it. Upload test.jpg and save the node.
2. Visit the node page so that the imagecache thumb is produced.
3. Remove the image associated with the imagefield and save the node.
4. Edit the same node again, and upload a different picture called test.jpg and save the node.
5. Visit this new nodes page and you'll notice a stale imagecache thumb.
drewish’s picture

There's no way that imagecache can know that the files changed via a hook because Drupal 6 doesn't have a standard notification mechanism for file events. In D7 there's hook_file_update() or hook_file_delete() that can tell us about changes.

If someone wants to roll a patch that compares the timestamp of the source file and the cached image and expires the cached image if it's older than the source file I'd be happy to review it.

voxpelli’s picture

StatusFileSize
new965 bytes

@drewish: hook_file_update() and hook_file_delete() isn't used by Drupal Core in 6.x - but they're actually used by Filefield and Imagefield and it might be a good idea to have imagecache support those hooks - then everyone wanting to tell imagecache that a file has been updated or changed could invoke the hooks and we would have a pretty standard way of talking between files that works very well with Drupal 7.

I'm adding a patch for that.

voxpelli’s picture

Status: Active » Needs review
drewish’s picture

voxpelli, not sure what you're rolling that against because I've already got a imagecache_file_delete() function. Update to HEAD and see if that takes care of it or if we really need to implement update as well.

voxpelli’s picture

Status: Needs review » Active

Sorry - my mistake - had missed that it has been added in the latest version - should've checked.

j0rd’s picture

Glad to see some eyes on this. I noticed a new imagecache was released a couple days ago and

"# #447402 by drewish: Not removing derivates for deleted filefield images." was in there.

http://drupal.org/node/447402

Is this the same issue as drewish has mentioned.

Thanks for all the work on this issue.

davepoon’s picture

I have tried all the suggested solutions(imagecache patches, filefield path module, file replace module, etc)
still can't fix the problem,
we still have to manually delete the files in imagefield_thumbs directory or flush the cache manually,
it is impossible/not user friendly for users or admin users to do that.

It is even more confusing when uploading multiple images,
if admin users reupload the images, or create a new node by uploading the same filename images,
the old thumbnails are displayed,
admin users are frustrated because of the thumbnail preview,
although they are working fine on the node page(the expected imagecache version of the images).

Same filename is needed sometimes,
in my case, I have to allow admin users to upload 8 images (page01.jpg, page02.jpg, etc),
and let a swf/Flash flipbook app to those 8 images with same filename (page01.jpg, page02.jpg, etc).
It will automatically generates an interactive flash flipbook on the page,
but currently, the thumbnail preview is really frustrating to those admin users...

Hope anyone could find a solution to solve the problem, and of course, I am also trying...
Thank you very much.

zoo’s picture

I encountered the problem described in #1, today.

Deleting an image previously uploaded and then uploading a new image completely different but with the same name of the one deleted, results in the old image still being displayed in the post (thumbnail and full size), as #1 described.

Is there any solution?

No one since january 2010 experienced this issue again? thanks.

zoo

j0rd’s picture

Zoo, have you cleared your browser cache? Do you still have this error.

Also what versions of Drupal, Filefield and Imagecache are you using?

zoo’s picture

Zoo, have you cleared your browser cache? Do you still have this error.

Yes, I have cleared both the browser and Drupal cache, still get the error.

Also what versions of Drupal, Filefield and Imagecache are you using?

It happens with Drupal 6.17 - Filefield 6.x-3.4 - Imagecache 6.x-2.0-beta10

j0rd’s picture

It appears the patch I mentioned in #18 was applied to imagecache "beta10". I assume it resolves the issue. I'd recommend adding some debug code into the imagecache.module function imagecache_file_delete hook:

Test if:
1. If the hook is getting called and the file exists.
2. If the file is gone after imagecache_image_flush is called.

If the hook is called and the file is not deleted, we have an issue in imagecache_image_flush I suppose.

You might have to do the work yourself zoo, as I think this is probably working for most people. At the very least, provide the comminity with the steps to duplicate this issue on a fresh install of Drupal 6.17, Filefield 3.4 and Imagecache 2.0-beta10 . You need to do this on a fresh install with only these minimal modules installed.

Cheers,
Jordan

zoo’s picture

Hello j0rd,

thank you, tried and didn't experienced the same problem using a fresh installation of Drupal.

Even though the problem remains in the official site...

zoo

j0rd’s picture

Then you got something bad floating around. Maybe try disabling modules which are related to this. Un-install them. Download them fresh. Re-enable them. Maybe something bad floating around in the old code or database tables.

Be sure to make backups first :D

zoo’s picture

Hello J0rd,

thank you, yes I know.

Unfortunately right now I've no time to go with the whole process, hoping the problem will heal itself :)

bye

zoo

YK85’s picture

subscribing - im having trouble with old thumbnails showing with the filename is the same

fizk’s picture

Priority: Critical » Normal
Status: Active » Closed (fixed)

Please reopen if this is still an issue with 6.x-2.0-rc1.