1 public function getReadableFileSize($retstring=null){ 2 3 $sizes = array(‘byte‘,‘kB‘,‘MB‘,‘GB‘,‘TB‘,‘PB‘,‘EB‘,‘ZB‘,‘YB‘); 4 5 if($retstring == null) 6 $retstring = "%01.2f %s"; 7 8 $lastsizestring = end($sizes); 9 10 foreach($sizes as $sizestring){ 11 if($this->size<1024) 12 break; 13 if($sizestring!=$lastsizestring) 14 $this->size/=1024; 15 } 16 17 if($sizestring == $sizes[0]) 18 $retstring = "%01d %s": 19 20 return sprintf($retstring,$this->size,$sizestring); 21 }
一个好的关于计算文件大小,及使其便于阅读的方法(php),布布扣,bubuko.com
原文地址:http://www.cnblogs.com/superzlc/p/3851917.html