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
This commit is contained in:
ryan 2007-07-15 17:52:50 +00:00
parent 17a5de92fe
commit d8d651221c
2 changed files with 19 additions and 1 deletions

View File

@ -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 .= "</a>\n";
$r .= "\t\t\t\t<span class='upload-file-size'>".size_format(filesize($filesystem_path))."</span>\n";
$r .= "\n\t\t<div class='upload-file-data'>\n\t\t\t<p>\n";
$r .= "\t\t\t\t<input type='hidden' name='attachment-url-$id' id='attachment-url-$id' value='$src' />\n";
$r .= "\t\t\t\t<input type='hidden' name='attachment-url-base-$id' id='attachment-url-base-$id' value='$src_base' />\n";

View File

@ -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);