Opened 21 months ago
Last modified 3 months ago
#54111 new defect (bug)
Delete attachment with sizes not working on Windows file system
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | 5.8.1 |
Component: | Media | Keywords: | reporter-feedback has-patch dev-feedback needs-testing needs-testing-info |
Focuses: | Cc: |
Description
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
wp_delete_attachment()
.
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
E:/folder1/folder2/folder3/wp-content/uploads/extra-folder/91010/65535_49693031347_cd702ea089_h_1280_700_nofilter-300x164.jpg
.
It is the full windows path including file.
After $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
the variable $intermediate_file
is equal
E:/folder1/folder2/folder3/wp-content/uploads/E:/folder1/folder2/folder3/wp-content/uploads/extra-folder/91010/65535_49693031347_cd702ea089_h_1280_700_nofilter-300x164.jpg
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
E:/folder1/folder2/folder3/wp-content/uploads/E:/folder1/folder2/folder3/wp-content/uploads/extra-folder/91010
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.
Attachments (1)
Change History (9)
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
21 months ago
This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.
21 months ago
#4
@
6 months ago
- Keywords reporter-feedback has-patch dev-feedback added
- Severity changed from critical to normal
#5
@
4 months ago
Thank you @bgoewert for your message and effort to fix this issue.
First of all sorry for my late reply.
I'm glad to tell you that your fix is working as expected. The patch will delete all attachment sizes on Windows.
Hope this fix will find its way into WordPress core with the next update.
Once again thank you for your time and effort!
Hello @kybernetikservices and welcome to WordPress Trac!
It's been 16 months since this was submitted. Are you still able to reproduce this issue? If so, can you provide a little more information about your environment, particularly the Windows Server and PHP version?
Looking into
path_join()
brings me to path_is_absolute() which implements some checks on the given path.If
E:/folder1/folder2/folder3/wp-content/uploads/extra-folder/91010/65535_49693031347_cd702ea089_h_1280_700_nofilter-300x164.jpg
was your actual path format, it seems like it would have failed all those checks. This is an invalid Windows path format (/
vs\
).One of the checks that
path_is_absolute()
performs usesrealpath()
which returns the correct path format, if this was a valid path. However,path_is_absolute()
checks the canonical path against the ill-formatted one that was given, meaning this would not match because the slashes are different.There is a Windows specific check as well. Although, this check does not take into account the ill-formatted path.
I would venture to guess that somewhere in your plugin, or in your environment, the slashes got reversed and caused this to fail.
What we could do is add
realpath()
to the Windows check to ensure it's using the correct path format.I've attached a patch for that and just need someone to review.
54111.patch