时间:2021-07-01 10:21:17 帮助过:11人阅读
文件大小显示,例如 1.7K , 2.9M
代码如下:
代码如下:// A much better and accurate version can be found
// in Aidan's PHP Repository:
// http://aidanlister.com/repos/v/function.size_readable.php
/**
* Returns a human readable filesize
*
* @author wesman20 (php.com)
* @author Jonas John
* @version 0.3
* @link http://www.jonasjohn.de/snippets/php/readable-filesize.htm
*/
function HumanReadableFilesize($size) {
// Adapted from: http://www.php.com/manual/en/function.filesize.php
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}
希望本文所述对大家的php程序设计有所帮助。