From d8d651221c6dec3ce5bb4f08227a1651410f60a9 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 15 Jul 2007 17:52:50 +0000 Subject: [PATCH] Show upload file size in upload browser. Props tellyworth. fixes #4561 git-svn-id: http://svn.automattic.com/wordpress/trunk@5801 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/upload.php | 4 +++- wp-includes/functions.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/upload.php b/wp-admin/includes/upload.php index 2dd7cb0f3..b09ff2fdf 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 0484b8794..21b917a3d 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);