Make WordPress Core

Opened 7 weeks ago

Closed 7 weeks ago

Last modified 7 weeks ago

#63180 closed defect (bug) (invalid)

Media Library Incorrectly Identifies Non-Identical Filenames as Duplicates

Reported by: zahnd's profile zahnd Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.7.2
Component: Media Keywords: needs-patch
Focuses: Cc:

Description

The WordPress Media Library's duplicate detection system incorrectly identifies files as duplicates when one filename is a substring of another, even though they are distinct files.

Steps to Reproduce:

  1. Upload an image named "101iw500501.jpg"
  2. Upload a different image named "500501.jpg"
  3. Observe that WordPress treats the second file as a duplicate of the first, appending a suffix (e.g., "-1")

This does not apply the other way around. If the image "500501.jpg" is uploaded first, the second image, "101iw500501.jpg," will be treated as a distinct, new image.

I noticed the issue the first time using the API to upload images and verified it using the WP backend and Media Manager.

Expected Behavior:

  • WordPress should only consider files as duplicates if their filenames are identical
  • "101iw500501.jpg" and "500501.jpg" should be treated as distinct files, as they represent different product SKUs

Impact:
In our case, we sync products from an external ERP into WooCommerce and keep data in sync. Therefore, if the second image is treated as a duplicate and stored with a suffix (-1, -2, etc.), it will not be recognized as an existing, matching image in the next sync run and will be continuously uploaded again with a new suffix.

Use Case Example:
In our WooCommerce integration:

  1. ERP sends image file names like "101iw500501.jpg"
  2. The corresponding image is named "101iw500501.jpg"
  3. Another product is sent with the image file "500501.jpg"
  4. WordPress renames it to "500501-1.jpg" because "101iw500501.jpg" exists
  5. The synchronization system fails to match the existing image in WordPress with the one sent from the ERP
  6. This requires manual intervention to correct the image-product association

Environment:

  • WordPress Version: 6.7.2
  • PHP Version: 8.1.31

Attachments (3)

WhatsApp Image 2025-03-26 at 09.00.03.jpeg (14.8 KB) - added by zahnd 7 weeks ago.
not-working order of image upload
WhatsApp Image 2025-03-26 at 09.01.37.jpeg (22.1 KB) - added by zahnd 7 weeks ago.
working order of image upload
Screenshot 2025-03-26 094403.png (23.7 KB) - added by pbiron 7 weeks ago.
screenshot of media library where the file renaming suggested by this ticket doesn't happen

Download all attachments as: .zip

Change History (6)

@zahnd
7 weeks ago

not-working order of image upload

@zahnd
7 weeks ago

working order of image upload

@pbiron
7 weeks ago

screenshot of media library where the file renaming suggested by this ticket doesn't happen

#1 @pbiron
7 weeks ago

  • Keywords reporter-feedback added

Hi @zahnd

Thanx for the report (and welcome to Trac)!

However, I'm not able to reproduce the situation of "500501.jpg" getting a "-1" appended to the filename.

I could be wrong, but I suspect you've got a plugin (or theme) that is hooking into the wp_unique_filename filter.

Have you tried with ALL plugins deactivated and a default theme (e.g., TT4)?

#2 @zahnd
7 weeks ago

  • Resolution set to invalid
  • Status changed from new to closed

Hi @pbiron

Thanks for your fast reply. You're completely right. Not an issue in WordPress. Sorry. The plugin causing the issue is "Image Regenerate & Select Crop". I'm going to notify them now.

Thanks and best regards, Stefan

#3 @pbiron
7 weeks ago

  • Keywords reporter-feedback removed

No problem. Glad you got things figured out.

Note: See TracTickets for help on using tickets.