php 文件大小格式化

忘了出处是哪儿 ,实现很巧妙

function filesize_formatted($path)
{
    $size = filesize($path);
    $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
    $power = $size > 0 ? floor(log($size, 1024)) : 0;
    return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
}

 

posted @ 2019-04-23 14:46  1553  阅读(107)  评论(0编辑  收藏  举报