diff --git a/wp-admin/includes/upload.php b/wp-admin/includes/upload.php index 2dd7cb0f34..b09ff2fdff 100644 --- a/wp-admin/includes/upload.php +++ b/wp-admin/includes/upload.php @@ -5,8 +5,9 @@ function wp_upload_display( $dims = false, $href = '' ) { $id = get_the_ID(); $attachment_data = wp_get_attachment_metadata( $id ); $is_image = (int) wp_attachment_is_image(); + $filesystem_path = get_attached_file( $id ); if ( !isset($attachment_data['width']) && $is_image ) { - if ( $image_data = getimagesize( get_attached_file( $id ) ) ) { + if ( $image_data = getimagesize( $filesystem_path ) ) { $attachment_data['width'] = $image_data[0]; $attachment_data['height'] = $image_data[1]; wp_update_attachment_metadata( $id, $attachment_data ); @@ -38,6 +39,7 @@ function wp_upload_display( $dims = false, $href = '' ) { $r .= "\t\t\t$innerHTML"; if ( $href ) $r .= "\n"; + $r .= "\t\t\t\t".size_format(filesize($filesystem_path))."\n"; $r .= "\n\t\t
\n\t\t\t

\n"; $r .= "\t\t\t\t\n"; $r .= "\t\t\t\t\n"; diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 0484b8794b..21b917a3d5 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -91,6 +91,22 @@ function number_format_i18n($number, $decimals = null) { return number_format($number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep']); } +function size_format($bytes, $decimals = null) { + // technically the correct unit names for powers of 1024 are KiB, MiB etc + // see http://en.wikipedia.org/wiki/Byte + $quant = array( + 'TB' => pow(1024, 4), + 'GB' => pow(1024, 3), + 'MB' => pow(1024, 2), + 'kB' => pow(1024, 1), + 'B' => pow(1024, 0), + ); + + foreach ($quant as $unit => $mag) + if ( intval($bytes) >= $mag ) + return number_format_i18n($bytes / $mag, $decimals) . ' ' . $unit; +} + function get_weekstartend($mysqlstring, $start_of_week) { $my = substr($mysqlstring,0,4); $mm = substr($mysqlstring,8,2);