note 91477 modified in function.filesize by danbrown
| From: | danbrown@php.net | Date: | Thu, 11 Jun 2009 19:17:31 +0000 |
| Subject: | note 91477 modified in function.filesize by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156785@lists.php.net to get a copy of this message | ||
a quick way to convert bytes to a more readable format can be done using this function:
<?php
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
?>
--was--
a quick way to convert bytes to a more readable format can be done using this function:
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
http://php.net/manual/en/function.filesize.php