On 02.07.12, In wordpress, by Samuel east
get attachment size n wordpress from id and display
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => getStorageID() //Post ID of Client Files page
);
$attachments = get_posts($args);
if ($attachments) { ?>
<?php foreach ($attachments as $attachment) { ?>
<?php echo _format_bytes(filesize( get_attached_file( $attachment->ID ) )); ?>
<?php } } ?>
And use this function in functions.php
function _format_bytes($a_bytes)
{
if ($a_bytes < 1024) {
return $a_bytes .' B';
} elseif ($a_bytes < 1048576) {
return round($a_bytes / 1024, 2) .' KiB';
} elseif ($a_bytes < 1073741824) {
return round($a_bytes / 1048576, 2) . ' MiB';
} elseif ($a_bytes < 1099511627776) {
return round($a_bytes / 1073741824, 2) . ' GiB';
} elseif ($a_bytes < 1125899906842624) {
return round($a_bytes / 1099511627776, 2) .' TiB';
} elseif ($a_bytes < 1152921504606846976) {
return round($a_bytes / 1125899906842624, 2) .' PiB';
} elseif ($a_bytes < 1180591620717411303424) {
return round($a_bytes / 1152921504606846976, 2) .' EiB';
} elseif ($a_bytes < 1208925819614629174706176) {
return round($a_bytes / 1180591620717411303424, 2) .' ZiB';
} else {
return round($a_bytes / 1208925819614629174706176, 2) .' YiB';
}
} 







Quick Signup And Connect
Enter your WordPress.com blog URL
http://.wordpress.com
Proceed