WordPress.org

Make WordPress Core

Ticket #19800: 19800.less-copying.diff

File 19800.less-copying.diff, 1.8 KB (added by duck_, 3 years ago)
  • wp-admin/includes/file.php

     
    323323 
    324324        $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); 
    325325 
    326         $tmp_file = wp_tempnam($filename); 
    327  
    328326        // Move the file to the uploads dir 
    329         if ( false === @ move_uploaded_file( $file['tmp_name'], $tmp_file ) ) 
     327        $new_file = $uploads['path'] . "/$filename"; 
     328        if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 
    330329                return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); 
    331330 
    332331        // If a resize was requested, perform the resize. 
    333332        $image_resize = isset( $_POST['image_resize'] ) && 'true' == $_POST['image_resize']; 
    334333        $do_resize = apply_filters( 'wp_upload_resize', $image_resize ); 
    335         $size = @getimagesize( $tmp_file ); 
    336         if ( $do_resize && $size ) { 
    337                 $old_temp = $tmp_file; 
    338                 $tmp_file = image_resize( $tmp_file, (int) get_option('large_size_w'), (int) get_option('large_size_h'), 0, 'resized'); 
    339                 if ( ! is_wp_error($tmp_file) ) { 
    340                         unlink($old_temp); 
    341                 } else { 
    342                         $tmp_file = $old_temp; 
     334        if ( $do_resize ) { 
     335                $resized = image_resize( $new_file, (int) get_option('large_size_w'), (int) get_option('large_size_h'), false, 'resized' ); 
     336                if ( is_wp_error( $resized ) || false === @ rename( $resized, $new_file ) ) { 
     337                        unlink( $new_file ); 
     338                        return $upload_error_handler( $file, __( 'The resized version could not be created.' ) ); 
    343339                } 
    344340        } 
    345341 
    346         // Copy the temporary file into its destination 
    347         $new_file = $uploads['path'] . "/$filename"; 
    348         copy( $tmp_file, $new_file ); 
    349         unlink($tmp_file); 
    350  
    351342        // Set correct file permissions 
    352343        $stat = stat( dirname( $new_file )); 
    353344        $perms = $stat['mode'] & 0000666;