- // A much better and accurate version can be found
- // in Aidan's PHP Repository:
- // <a href="http://aidanlister.com/repos/v/function.size_readable.php">http://aidanlister.com/repos/v/function.size_readable.php
- /**
- * Returns a human readable filesize
- *
- * @author wesman20 (php.net)
- * @author Jonas John
- * @version 0.3
- * @link <a href="http://www.jonasjohn.de/snippets/php/readable-filesize.htm">http://www.jonasjohn.de/snippets/php/readable-filesize.htm
- */
- function HumanReadableFilesize($size) {
- // Adapted from: <a href="http://www.php.net/manual/en/function.filesize.php">http://www.php.net/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];
- }
- //该片段来自于http://www.codesnippet.cn/detail/21112012517.html
来源: http://www.codesnippet.cn/detail/21112012517.html