Ticket #33053: 33053.diff
File 33053.diff, 2.6 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/file.php
function list_files( $folder = '', $leve 139 139 * 140 140 * @param string $filename Optional. Filename to base the Unique file off. Default empty. 141 141 * @param string $dir Optional. Directory to store the file in. Default empty. 142 142 * @return string a writable filename 143 143 */ 144 144 function wp_tempnam( $filename = '', $dir = '' ) { 145 145 if ( empty( $dir ) ) { 146 146 $dir = get_temp_dir(); 147 147 } 148 148 149 149 if ( empty( $filename ) || '.' == $filename || '/' == $filename ) { 150 150 $filename = time(); 151 151 } 152 152 153 153 // 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 ); 156 155 157 156 // If the folder is falsey, use it's parent directory name instead 158 157 if ( ! $temp_filename ) { 159 158 return wp_tempnam( dirname( $filename ), $dir ); 160 159 } 161 160 162 161 $temp_filename .= '.tmp'; 163 162 $temp_filename = $dir . wp_unique_filename( $dir, $temp_filename ); 164 163 touch( $temp_filename ); 165 164 166 165 return $temp_filename; 167 166 } 168 167 169 168 /** 170 169 * Make sure that the file that was requested to edit, is allowed to be edited … … function wp_handle_sideload( &$file, $ov 442 441 /** 443 442 * Downloads a url to a local temporary file using the WordPress HTTP Class. 444 443 * Please note, That the calling function must unlink() the file. 445 444 * 446 445 * @since 2.5.0 447 446 * 448 447 * @param string $url the URL of the file to download 449 448 * @param int $timeout The timeout for the request to download the file default 300 seconds 450 449 * @return mixed WP_Error on failure, string Filename on success. 451 450 */ 452 451 function download_url( $url, $timeout = 300 ) { 453 452 //WARNING: The file is not automatically deleted, The script must unlink() the file. 454 453 if ( ! $url ) 455 454 return new WP_Error('http_no_url', __('Invalid URL Provided.')); 456 455 457 $tmpfname = wp_tempnam( $url);456 $tmpfname = wp_tempnam( parse_url( $url, PHP_URL_PATH ) ); 458 457 if ( ! $tmpfname ) 459 458 return new WP_Error('http_no_file', __('Could not create Temporary file.')); 460 459 461 460 $response = wp_safe_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) ); 462 461 463 462 if ( is_wp_error( $response ) ) { 464 463 unlink( $tmpfname ); 465 464 return $response; 466 465 } 467 466 468 467 if ( 200 != wp_remote_retrieve_response_code( $response ) ){ 469 468 unlink( $tmpfname ); 470 469 return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) ); 471 470 } 472 471