当meta不可用时,这2个函数将与自定义mime上载文件(如PSD、EPS)一起使用。它还返回更多的字节,即2个十进制逻辑单元。99将最后一个信息放在元框中。
// Helper
function ua_formatBytes($bytes, $precision = 2) {
$units = array(\'B\', \'kB\', \'mB\', \'GB\', \'TB\');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . \' \' . $units[$pow];
}
// Hooked
function ua_admin_custom_filesize_on_edit_media_screen() {
global $post; // $post = get_post();
$filesize = @filesize(get_attached_file($post->ID));
if ( ! empty( $filesize ) && is_numeric( $filesize ) && $filesize > 0 ) : ?>
<div class="misc-pub-section">
<?php _e( \'File size:\' ); ?> <strong><?php echo ua_formatBytes( $filesize ); ?></strong>
</div>
<?php
endif;
}
add_action( \'attachment_submitbox_misc_actions\', \'ua_admin_custom_filesize_on_edit_media_screen\', 99 );