From 28ab6b95788489ee7fcbeab717397350cde2ad39 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 9 Nov 2015 00:44:01 +0000 Subject: [PATCH] Media: Allow `media_sideload_image()` to work when the upload directory is a PHP Stream. Using copy() instead of rename() allows the function to work across different stream sources. Props mattheu. Fixes #29257 git-svn-id: https://develop.svn.wordpress.org/trunk@35579 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/file.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index a37ead892f..1cd0e4ca3d 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -345,7 +345,9 @@ function _wp_handle_upload( &$file, $overrides, $time, $action ) { if ( 'wp_handle_upload' === $action ) { $move_new_file = @ move_uploaded_file( $file['tmp_name'], $new_file ); } else { - $move_new_file = @ rename( $file['tmp_name'], $new_file ); + // use copy and unlink because rename breaks streams. + $move_new_file = @ copy( $file['tmp_name'], $new_file ); + unlink( $file['tmp_name'] ); } if ( false === $move_new_file ) {