Ticket #21292: 21292-3.diff
File 21292-3.diff, 5.4 KB (added by , 13 years ago) |
---|
-
wp-includes/functions.php
1576 1576 * @param null $deprecated Never used. Set to null. 1577 1577 * @param mixed $bits File content 1578 1578 * @param string $time Optional. Time formatted in 'yyyy/mm'. 1579 * @param array $additional_args Optional. Additional arguments. 1579 1580 * @return array 1580 1581 */ 1581 function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {1582 function wp_upload_bits( $name, $deprecated, $bits, $time = null, $additional_args = false ) { 1582 1583 if ( !empty( $deprecated ) ) 1583 1584 _deprecated_argument( __FUNCTION__, '2.0' ); 1584 1585 1586 $default_additional_args = array( 'validate_extension' => true, 'mimes' => false ); 1587 $additional_args = wp_parse_args( $additional_args, $default_additional_args ); 1588 1585 1589 if ( empty( $name ) ) 1586 1590 return array( 'error' => __( 'Empty filename' ) ); 1587 1591 1588 $wp_filetype = wp_check_filetype( $name );1589 if ( !$wp_filetype['ext'] )1590 return array( 'error' => __( 'Invalid file type' ) );1591 1592 1592 $upload = wp_upload_dir( $time ); 1593 1593 1594 1594 if ( $upload['error'] !== false ) 1595 1595 return $upload; 1596 1596 1597 1597 $upload_bits_error = apply_filters( 'wp_upload_bits', array( 'name' => $name, 'bits' => $bits, 'time' => $time ) ); 1598 if ( ! is_array( $upload_bits_error) ) {1598 if ( ! is_array( $upload_bits_error ) || isset( $upload_bits_error['error'] ) ) { 1599 1599 $upload[ 'error' ] = $upload_bits_error; 1600 1600 return $upload; 1601 1601 } … … 1617 1617 clearstatcache(); 1618 1618 1619 1619 // Set correct file permissions 1620 $stat = @stat( dirname( $new_file ) );1620 $stat = stat( dirname( $new_file ) ); 1621 1621 $perms = $stat['mode'] & 0007777; 1622 1622 $perms = $perms & 0000666; 1623 1623 @ chmod( $new_file, $perms ); 1624 1624 clearstatcache(); 1625 1625 1626 // Attempt to validate the extension as being correct 1627 if ( $additional_args['validate_extension'] ) { 1628 $wp_filetype = wp_check_filetype_and_ext( $new_file, $name, $additional_args['mimes'] ); 1629 1630 extract( $wp_filetype ); 1631 1632 // This will be set if the original filename was invalid 1633 if ( $proper_filename ) { 1634 $filename = wp_unique_filename( $upload['path'], $proper_filename ); 1635 $new_file_path = $upload['path'] . "/$filename"; 1636 rename( $new_file, $new_file_path ); 1637 $new_file = $new_file_path; 1638 } 1639 1640 if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) { 1641 unlink( $new_file ); 1642 return array( 'error' => __( 'Sorry, this file type is not permitted for security reasons.' ) ); 1643 } 1644 } 1645 else { 1646 $type = false; 1647 } 1648 1626 1649 // Compute the URL 1627 1650 $url = $upload['url'] . "/$filename"; 1628 1651 1629 return array( 'file' => $new_file, 'url' => $url, 'error' => false ); 1652 if ( is_multisite() ) 1653 delete_transient( 'dirsize_cache' ); 1654 1655 return array( 'file' => $new_file, 'url' => $url, 'type' => $type, 'error' => false ); 1630 1656 } 1631 1657 1632 1658 /** -
wp-includes/class-wp-xmlrpc-server.php
4557 4557 } 4558 4558 4559 4559 $upload = wp_upload_bits($name, null, $bits); 4560 4560 4561 if ( ! empty($upload['error']) ) { 4561 4562 $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']); 4562 4563 return new IXR_Error(500, $errorString); 4563 4564 } 4565 4566 if( $upload['type'] ) 4567 $type = $upload['type']; 4568 4564 4569 // Construct the attachment array 4565 4570 // attach to post_id 0 4566 4571 $post_id = 0; -
wp-admin/includes/ms.php
19 19 if ( get_site_option( 'upload_space_check_disabled' ) ) 20 20 return $file; 21 21 22 if ( $file['error'] != '0' ) // there's already an error22 if ( isset( $file['error'] ) && $file['error'] != '0' ) // there's already an error 23 23 return $file; 24 24 25 25 if ( defined( 'WP_IMPORTING' ) ) … … 28 28 $space_allowed = 1048576 * get_space_allowed(); 29 29 $space_used = get_dirsize( BLOGUPLOADDIR ); 30 30 $space_left = $space_allowed - $space_used; 31 $file_size = filesize( $file['tmp_name'] ); 32 if ( $space_left < $file_size ) 31 32 if( 'wp_upload_bits' == current_filter() ) { 33 if( function_exists( 'mb_strlen' ) ) 34 $file_size = mb_strlen( $file['bits'], 'ascii'); 35 else 36 $file_size = strlen( $file['bits'] ); 37 } 38 else { 39 $file_size = filesize( $file['tmp_name'] ); 40 } 41 42 if( $space_left < $file_size ) 33 43 $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) ); 34 if 44 if( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) 35 45 $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) ); 36 if 46 if( upload_is_user_over_quota( false ) ) { 37 47 $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' ); 38 48 } 39 if ( $file['error'] != '0' && !isset($_POST['html-upload']) )49 if( 'wp_handle_upload_prefilter' == current_filter() && $file['error'] != '0' && ! isset( $_POST['html-upload'] ) ) 40 50 wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' ); 41 51 42 52 return $file; 43 53 } 44 54 add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' ); 55 add_filter( 'wp_upload_bits', 'check_upload_size' ); 45 56 46 57 /** 47 58 * Delete a blog