I'm using imagefield to create image galleries. Sometimes imagefield does a renaming of the original file when uploading, adding a suffix _0 (i.e original file "image.jpg" gets renamed to image_0.jpg).

Problem is, imagefield keeps the original filename so when I try to reference the file (image) I get no image. Which, by the way, is the correct behaviur, because there is no file in the filesystem by that name.

Can somebody tell me what is going on?

(I would think that renaming of images should only appear when there is already an image by the same name in the upload folder!)

CommentFileSizeAuthor
#7 wrong.filename.png34.04 KBjack.r.abbit

Comments

quicksketch’s picture

Category: bug » support

Most likely, there already is an image with the same name. ImageField only renames images if there is a naming conflict. If you upload image.jpg, save, then edit and remove image.jpg and upload a new image.jpg, the second image.jpg will be named image_0.jpg even though you've removed the first one. This is because if you did not save the node, or if you save a new revision, the original image.jpg is still needed.

gadehans’s picture

But you would think that a file renaming should be reflected in the imagefield filename. It is not.

The imagefield "filepath" gets it right, but not the "filename"

quicksketch’s picture

This is Drupal's default behavior for conflicting file names. See http://api.drupal.org/api/function/file_save_upload/6

If you'd like to show the true file name, you can theme the theme_filefield_file() function and use basename($item['filepath']) to show the real file name.

jack.r.abbit’s picture

We have been facing the same issue with files getting renamed with the _0 but the renaming it not reflected. After doing a bunch of testing with different scenarios, we were able to consistently reproduce what the client was doing. At first we thought it was just what you said about saving the node after remove but before uploading again. And yes that solved it for that particular use case. However, it still pointed to a greater problem so we kept on testing. The same things happens when uploading files with the same name to two different nodes.

Use case:
Try uploading two separate images with the same name to two separate nodes. The first one will work as expected. The second one will have its file renamed as expected but the system will still remember the original name. Now we have a problem. I would say that makes this a Bug Report.

quicksketch’s picture

I still can't reproduce this problem. Here are my steps:

- Visit node/add/story (on which a FileField has been set up)
- Visit node/add/story in a separate window.
- Upload example.jpg in the first window. The file has the name example.jpg both in the database and on the disk.
- Upload example.jpg in the second window. The file has the name example_0.jpg both in the database and on the disk.
- Save node 1.
- Save node 2.

Both nodes are referencing entirely different images, both with separate names and different entries in the database. As far as I can tell, there is no bug in FileField.

Please note that FileField Paths does have a similar bug. If you're using that module, you're probably experiencing this problem: #478646: Wrong thumbnail shown after upload if creating more than one node and the same file name..

quicksketch’s picture

Note that #4 is different than the original issue here, which was reporting that the filename was incorrect (say it'd be example.jpg for both in my above example), but the file displayed was always correct since the filepath is accurate. As I said this difference is due to Drupal's handling of files in core. It's the intentional behavior used throughout Drupal.

jack.r.abbit’s picture

StatusFileSize
new34.04 KB

The OP clearly states: 'Problem is, imagefield keeps the original filename...' and 'The imagefield "filepath" gets it right, but not the "filename"'

This is the same problem listed in #4. I've posted a screen shot of the DB entries for the example use case described in #4. Notice that both have the correct value for filepath but the last entry keeps the original filename. Because of this, "filename" in the DB can never be trusted... rendering it useless. Perhaps this is just the way that Drupal handles the naming of duplicate file and not a bug with this (or any) module. I don't think it makes sense to retain the original filename in the database.

quicksketch’s picture

Oh, yes then it is exactly the same problem. However that's the way Drupal saves files throughout the whole system. See #3.

quicksketch’s picture

Status: Active » Closed (works as designed)
Futureshox’s picture

I'm running into the same issue but with "deleted" content. When I add a file to the site the URL is often referenced in published documentation so the URL needs to be consistent. I have run across an issue that when I delete a piece of content (due to a mistake or corrupted file) - Drupal remembers the URL it was formerly posted as, so if I try to add the content correctly an added "_0" or "_1" is appended to the URL of the new file making the references to it break.
Is there a way to COMPLETELY remove the content from the Drupal database so that it was like it was never initially uploaded and saved? ANY help here would be greatly appreciated by this Drupal noob :)