number_format()这个函数是干什么的?
<?php $filename = '/data/webroot/usercode/code/resource/test.txt'; //取得文件的大小并输出 $size = filesize($filename); function getsize($size, $format = 'kb') { $p = 0; if ($format == 'kb') { $p = 1; } elseif ($format == 'mb') { $p = 2; } elseif ($format == 'gb') { $p = 3; } $size /= pow(1024, $p); return number_format($size, 3); } $size = filesize($filename); $size = getsize($size, 'kb'); //进行单位转换 echo $size.'kb';