I'm uploading 2 different images, both has the same filename on my computer.
the first is uploaded as "testtest1.jpg" and the second is uploaded as "testtest1_0.jpg"
each image is uploaded within a different node.

I have one imagecache preset, that i use in the node view, but only one of the pictures is being processed by the preset.
this causes the same image to be shown in two different nodes.

wanted behavior - the module will process images by it's file name on the disk (and not in DB as it does now).

Comments

dopry’s picture

Do you get the same behavior with imagecache disabled?

dopry’s picture

Status: Active » Postponed (maintainer needs more info)
elyobo’s picture

I have the same problem with duplicate file names. I had to bring across all my data from another website and have duplicate filenames.

I've modified the image module on my personal install to prefix the thumbnail and preview images with the node id, which has resolved most of my problems. However, if I go in and edit an image node (to add tags, or change the title etc). then the automatically generated filename does _not_ include the node id, so duplicates happen again. I suspect this is a problem in the upload module, rather than the image module.

Generating a unique name for image thumbnails and previews seems like a sensible idea.

dopry’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

So this is actually a D5 file handling bug and caching issue... So I'm going to explain the problem... and then mark it won't fix as it only applies to 5.x and a particularly difficult edge case...

1) when a file is first uploaded it isn't stored on the file system until the node is saved... so we make up a url for it based on where it should be stored on the filesystem. if you upload two files with the same name there isn't a file for it to conflict with so the url we generate doesn't get the _0 it would when we generate the filename if there is another file it would clash with.

2) I cannot know if one or the other will be deleted before the node is submitted. There could also be other people uploading files of the same name.. (You can explore this but by doing concurrent uploads with upload.module the generated file urls for preview will be incorrect.)

3) The views on the admin page requests the preview images and they have a cache-control set in the future... This is do the files are re-downloaded everytime you hit preview/attach buttons. This had a big impact on site performance and on usability...

4) I think two images with the same name on the same node at the same time is a far edge case and too much work will go into working around it in imagefield when it had already been resolved in the core file handling for D6.

gagarine’s picture

Version: 5.x-1.3 » 6.x-2.0-beta1

I have the same problem on D6

pentike’s picture

Version: 6.x-2.0-beta1 » 5.x-1.7
Status: Closed (won't fix) » Needs review
StatusFileSize
new1.93 KB

Hi!

Here is a patch we have made to fix this issue at www.zeneszapro.hu where we have a lot of images and in some categories users often call them i.e. guitar.jpg, so unfortunately this was not a marginal problem for us.

The patch uses a database table to keep a diary of the created cache files since other file related modules delete the files from the image table before hook_nodeapi of imagecache could reach them.
The zipped file contains the patch files for the 1.3 and 1.7 versions of the module and the 1.7 version of the install file which creates the database tables and PUTS ALL CURRENT IMAGES IN THE CACHE LOG.

Hope it helps others too!
Regards,
Gábor

drewish’s picture

Status: Needs review » Needs work

don't attach zip files. roll a patch. if you need help consult http://drupal.org/patch/create

wadmiraal’s picture

Title: duplicate file name, but different image - only one is processed » duplicate file name
Version: 5.x-1.7 » 6.x-2.0-beta9
Status: Needs work » Active

Hi,

I'm going to re-open this issue. I have this problem with Drupal 6 (module version 6.x-2.0-beta 9) and all those solutions in #6 to #8 seem overkill to me.

Indeed, when two images, with the same name, are uploaded, they use the same image created by ImageCache (for the same profile, obviously). This is clearly a "problem" with ImageCache, as the files that are uploaded are always sufixed when encountering another file with the same name.

I don't really understood your explanation in #4, but because it was for Drupal 5, I guess it doesn't really apply here.

Does ImageCache get the filename from the DB or directly from the node object ? In both cases, instead of relying on the filename, it could use the filepath to name the new image. Just use a substring - from the last / onward. There's your correct filename. And the problem will be solved.

Is that at all possible or am I completely mistaking ?

P.S. Great module btw ! Great this is coming to core !

wadmiraal’s picture

Status: Active » Needs work

Sorry, got the status wrong...

wadmiraal’s picture

Ok, sorry.

Reading through your code, I understand why this could be quite complex to implement...

The solution, although not very elegant, would be to use imagecache_create_url() instead of theme('imagecache') in our template files (ehw!).

That's what I did for now. At least it works. If you have a better suggestion, please let me know.

Cheers

wadmiraal’s picture

@antony09

Completely off topic. You should read the problem first. We're not talking about duplicate files on the system, but in the database.

floridaproject’s picture

$75 bounty if someone can fix this in an elegant way. Any takers? People on our site are ending up with other people's images if the filename is the same.

fizk’s picture

Priority: Critical » Normal
Status: Needs work » Closed (fixed)

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