- <?php
- function getsize($size, $format) {
- $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);
- }
- $filename = '/data/webroot/usercode/code/resource/test.txt';
- $size = filesize($filename);
- $size = getsize($size, 'kb'); //进行单位转换
- echo $size.'kb';