Make WordPress Core

Opened 5 years ago

Last modified 2 years ago

#49042 new defect (bug)

After WordPress automatically scales your uploaded images down, it loses track of the original images

Reported by: pikamander2's profile pikamander2 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3
Component: Upload Keywords: reporter-feedback
Focuses: Cc:

Description

WordPress 5.3's new image scaling feature seems to have an overlooked issue.

  1. Go to /wp-admin/upload.php
  1. Upload a huge image.
  1. WordPress will resize the image automatically and call your image (filename)-scaled.jpg
  1. Go back to /wp-admin/upload.php
  1. Delete the image permanently
  1. Upload a new image with that same filename
  1. The new image will now have "-1" attached to the end of it, because WordPress didn't delete the original (non-resized) image from the uploads folder.

There doesn't appear to be any way to remedy this via the UI, and it's bound to lead to both confusion and unnecessary files piling up on people's servers.

The best solution here, I think, would be to store the name of the original file somewhere (if it's not already being stored) and delete it too when somebody deletes the scaled image.

Change History (1)

#1 @azaozz
5 years ago

  • Keywords reporter-feedback added

The best solution here, I think, would be to store the name of the original file somewhere (if it's not already being stored) and delete it too when somebody deletes the scaled image.

This is exactly how it works :) The name of the original image is stored in the image meta, and the image is deleted with the attachment post and the rest of the image sub-sizes: https://core.trac.wordpress.org/browser/tags/5.3.2/src/wp-includes/post.php#L5691.

Unfortunately that's not easy to debug. If you have FTP access to your site, perhaps try uploading a (large) image 2-3 times and monitor the uploads directory. Then delete the attachments one by one and see if some files are left behind. If you have access to the database, can also check what's saved in the image meta (in the *_postmeta table, look for the latest _wp_attachment_metadata meta key after you upload the image).

If not, I'll try to make a quick plugin to expose some of that somewhere in the admin :)

Note: See TracTickets for help on using tickets.