Make WordPress Core

Opened 11 months ago

Last modified 11 months ago

#54111 new defect (bug)

Delete attachment with sizes not working on Windows file system

Reported by: kybernetikservices's profile kybernetikservices Owned by:
Milestone: Awaiting Review Priority: normal
Severity: critical Version: 5.8.1
Component: Media Keywords:
Focuses: Cc:


I wrote a custom plugin for importing data, including media files, from a CRM system. The media files are stored in a dedicated folder in wp-content/uploads.
When I delete a custom post I do also delete the attached media files with
I noted, on a Windows server, that just the primary image file will be deleted. All related image sizes are not deleted.

I debuged the function wp_delete_attachment_files() in wp-includes/post.php and figured out there is something wrong with the function path_join() (see code line 6240).
Before path_join() the variable $intermediate_file is


It is the full windows path including file.
After $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file ); the variable $intermediate_file is equal


Please check the path. It has added the full $intermediate_file to the $uploadpath['basedir'].
Same happen with the $intermediate_dir. After usign path_join() (line 6234) the path is


As you can see, it is the $uploadpath['basedir'] followed by the full folder path.

The same code is working on a linux server as expected.

Please let me know if I can give you more details to reproduce and fix this error.

Thanks for all your effort.

Change History (3)

#1 @SergeyBiryukov
11 months ago

  • Component changed from General to Media

This ticket was mentioned in Slack in #core-media by antpb. View the logs.

11 months ago

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.

11 months ago

Note: See TracTickets for help on using tickets.