#46487 closed defect (bug) (duplicate)
wp_delete_file_from_directory doesn't work with stream wrappers
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Filesystem API | Keywords: | has-patch |
Focuses: | Cc: |
Description
Since PHP realpath
doesn't support stream wrappers, you won't be able to delete a file that uses stream wrappers.
We can check if the file is using stream wrappers using the wp_is_stream( $file )
and avoid parsing the realpath
.
<?php function wp_delete_file_from_directory( $file, $directory ) { $file_path = wp_normalize_path( $file ) ; $directory_path = wp_normalize_path( $directory ) ; if ( ! wp_is_stream( $file ) ) { $real_file = realpath( $file_path ); $real_directory = realpath( $directory_path ); if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) { return false; } } if ( strpos( $file_path, trailingslashit( $directory_path ) ) !== 0 ) { return false; } wp_delete_file( $file ); return true;
Attachments (2)
Change History (9)
Note: See
TracTickets for help on using
tickets.
This appears to be a duplicate of #44563, now fixed in [45177].
@vtemian, could you test the changes made in [45177]?