From 9e8a91cd051b5a965b1d590164bdd0a4a0e688b0 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Fri, 21 Jun 2013 02:29:26 +0000 Subject: [PATCH] Show a relative path in an upload error message. git-svn-id: https://develop.svn.wordpress.org/trunk@24463 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/file.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 00ddc37863..c220586c35 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -328,8 +328,14 @@ function wp_handle_upload( &$file, $overrides = false, $time = null ) { // Move the file to the uploads dir $new_file = $uploads['path'] . "/$filename"; - if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) - return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); + if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) { + if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) + $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; + else + $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; + + return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $error_path ) ); + } // Set correct file permissions $stat = stat( dirname( $new_file )); @@ -452,7 +458,11 @@ function wp_handle_sideload( &$file, $overrides = false, $time = null ) { // Move the file to the uploads dir $new_file = $uploads['path'] . "/$filename"; if ( false === @ rename( $file['tmp_name'], $new_file ) ) { - return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); + if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) + $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; + else + $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; + return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $error_path ) ); } // Set correct file permissions