From d77f9aee99c3dfdbb33198151cc12781ead122d4 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 28 Aug 2007 23:13:16 +0000 Subject: [PATCH] Take post_max_size into account when determining the upload limit. Props mdawaffe. fixes #4240 git-svn-id: https://develop.svn.wordpress.org/trunk@5964 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/template.php | 35 ++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) 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 ); ?>

- ( ) + ()