[wp-trac] [WordPress Trac] #46487: wp_delete_file_from_directory doesn't work with stream wrappers
WordPress Trac
noreply at wordpress.org
Thu Mar 14 13:31:13 UTC 2019
#46487: wp_delete_file_from_directory doesn't work with stream wrappers
----------------------------+-----------------------------
Reporter: vtemian | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Filesystem API | Version:
Severity: normal | Keywords:
Focuses: |
----------------------------+-----------------------------
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
<?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;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46487>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list