php获取文件大小的方法

2019-11-16,,

复制代码 代码如下:
static function convert($size) {
        $unit=array('b','kb','mb','gb','tb','pb');
        return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
    }

也可用下面这种方法

复制代码 代码如下:

/**
 * Returns a human readable filesize
 */
function HumanReadableFilesize($size) {
    $mod = 1024;
    $units = explode(' ','B KB MB GB TB PB');
    for ($i = 0; $size > $mod; $i++) {
        $size /= $mod;
    }
    return round($size, 2) . ' ' . $units[$i];
}

《php获取文件大小的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。