Heim  >  Artikel  >  php教程  >  PHP 使用适合阅读的格式显示文件大小

PHP 使用适合阅读的格式显示文件大小

PHP中文网
PHP中文网Original
2016-05-25 17:15:481137Durchsuche

PHP 使用适合阅读的格式显示文件大小

// 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.net)
 * @author      Jonas John
 * @version     0.3
 * @link        http://www.jonasjohn.de/snippets/php/readable-filesize.htm
 */
function HumanReadableFilesize($size) {
 
    // Adapted from: 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];
}

                   

 以上就是PHP 使用适合阅读的格式显示文件大小的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn