头像

php 文件大小格式化

2018-04-17 11:27:01 浏览()   来源:http://www.phpdaima.com//jsfx-66.html   评论 ( 0 )   

/**
 * 文件大小格式化
 * @param integer $size 初始文件大小,单位为byte
 * @return array 格式化后的文件大小和单位数组,单位为byte、KB、MB、GB、TB
 */
function file_size_format($size = 0, $dec = 2) {
    $unit = array("B", "KB", "MB", "GB", "TB", "PB");
    $pos = 0;
    while ($size >= 1024) {
        $size /= 1024;
        $pos++;
    }
    $result['size'] = round($size, $dec);
    $result['unit'] = $unit[$pos];
    return $result['size'].$result['unit'];
}
echo file_size_format(123456789);


标签: php
广告不存在
评论0

后面还有条评论,点击查看>>

温馨提示:为规范评论内容,垃圾评论一律封号...