网络编程
位置:首页>> 网络编程>> php编程>> php获取文件大小的方法

php获取文件大小的方法

  发布时间:2024-05-13 09:26:15 

标签:php,文件

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];
}
0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com