[PHP] PHP 自动转换文件大小单位B KB MB GB TB PB →→→→→进入此内容的聊天室

来自 , 2019-12-06, 写在 PHP, 查看 104 次.
URL http://www.code666.cn/view/95177e52
  1. // A much better and accurate version can be found
  2. // in Aidan's PHP Repository:
  3. // http://aidanlister.com/repos/v/function.size_readable.php
  4.  
  5. /**
  6.  * Returns a human readable filesize
  7.  *
  8.  * @author      wesman20 (php.net)
  9.  * @author      Jonas John
  10.  * @version     0.3
  11.  * @link        http://www.jonasjohn.de/snippets/php/readable-filesize.htm
  12.  */
  13. function HumanReadableFilesize($size) {
  14.  
  15.     // Adapted from: http://www.php.net/manual/en/function.filesize.php
  16.  
  17.     $mod = 1024;
  18.  
  19.     $units = explode(' ','B KB MB GB TB PB');
  20.     for ($i = 0; $size > $mod; $i++) {
  21.         $size /= $mod;
  22.     }
  23.  
  24.     return round($size, 2) . ' ' . $units[$i];
  25. }

回复 "PHP 自动转换文件大小单位B KB MB GB TB PB"

这儿你可以回复上面这条便签

captcha