diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 0ea9202ea1..ce15ae2aca 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -559,21 +559,36 @@ function wp_dropdown_roles( $default = false ) { echo $p . $r; } +function wp_convert_hr_to_bytes( $size ) { + $size = strtolower($size); + $bytes = (int) $size; + if ( strpos($size, 'k') !== false ) + $bytes = intval($size) * 1024; + elseif ( strpos($size, 'm') !== false ) + $bytes = intval($size) * 1024 * 1024; + elseif ( strpos($size, 'g') !== false ) + $bytes = intval($size) * 1024 * 1024 * 1024; + return $bytes; +} + +function wp_convert_bytes_to_hr( $bytes ) { + $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' ); + $log = log( $bytes, 1024 ); + $power = (int) $log; + $size = pow(1024, $log - $power); + return $size . $units[$power]; +} + function wp_import_upload_form( $action ) { - $size = strtolower( ini_get( 'upload_max_filesize' ) ); - $bytes = 0; - if (strpos($size, 'k') !== false) - $bytes = $size * 1024; - if (strpos($size, 'm') !== false) - $bytes = $size * 1024 * 1024; - if (strpos($size, 'g') !== false) - $bytes = $size * 1024 * 1024 * 1024; - $size = apply_filters( 'import_upload_size_limit', $size ); + $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) ); + $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) ); + $bytes = apply_filters( 'import_upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes ); + $size = wp_convert_bytes_to_hr( $bytes ); ?>

- ( ) + ()