您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> php编程 >> 正文

获取文件大小的php代码

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   第一种

  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];

  }