WordPress.org

Make WordPress Core

Ticket #33053: 33053.diff

File 33053.diff, 2.6 KB (added by dd32, 5 years ago)
  • src/wp-admin/includes/file.php

    function list_files( $folder = '', $leve 
    139139 *
    140140 * @param string $filename Optional. Filename to base the Unique file off. Default empty.
    141141 * @param string $dir      Optional. Directory to store the file in. Default empty.
    142142 * @return string a writable filename
    143143 */
    144144function wp_tempnam( $filename = '', $dir = '' ) {
    145145        if ( empty( $dir ) ) {
    146146                $dir = get_temp_dir();
    147147        }
    148148
    149149        if ( empty( $filename ) || '.' == $filename || '/' == $filename ) {
    150150                $filename = time();
    151151        }
    152152
    153153        // Use the basename of the given file without the extension as the name for the temporary directory
    154         $temp_filename = basename( $filename );
    155         $temp_filename = preg_replace( '|\.[^.]*$|', '', $temp_filename );
     154        list( $temp_filename ) = explode( '.', basename( $filename ), 2 );
    156155
    157156        // If the folder is falsey, use it's parent directory name instead
    158157        if ( ! $temp_filename ) {
    159158                return wp_tempnam( dirname( $filename ), $dir );
    160159        }
    161160
    162161        $temp_filename .= '.tmp';
    163162        $temp_filename = $dir . wp_unique_filename( $dir, $temp_filename );
    164163        touch( $temp_filename );
    165164
    166165        return $temp_filename;
    167166}
    168167
    169168/**
    170169 * Make sure that the file that was requested to edit, is allowed to be edited
    function wp_handle_sideload( &$file, $ov 
    442441/**
    443442 * Downloads a url to a local temporary file using the WordPress HTTP Class.
    444443 * Please note, That the calling function must unlink() the file.
    445444 *
    446445 * @since 2.5.0
    447446 *
    448447 * @param string $url the URL of the file to download
    449448 * @param int $timeout The timeout for the request to download the file default 300 seconds
    450449 * @return mixed WP_Error on failure, string Filename on success.
    451450 */
    452451function download_url( $url, $timeout = 300 ) {
    453452        //WARNING: The file is not automatically deleted, The script must unlink() the file.
    454453        if ( ! $url )
    455454                return new WP_Error('http_no_url', __('Invalid URL Provided.'));
    456455
    457         $tmpfname = wp_tempnam($url);
     456        $tmpfname = wp_tempnam( parse_url( $url, PHP_URL_PATH ) );
    458457        if ( ! $tmpfname )
    459458                return new WP_Error('http_no_file', __('Could not create Temporary file.'));
    460459
    461460        $response = wp_safe_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) );
    462461
    463462        if ( is_wp_error( $response ) ) {
    464463                unlink( $tmpfname );
    465464                return $response;
    466465        }
    467466
    468467        if ( 200 != wp_remote_retrieve_response_code( $response ) ){
    469468                unlink( $tmpfname );
    470469                return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
    471470        }
    472471