The PHP website created by its users!
Home
»
PHP » human readable byte format
|
human readable byte format
| Author | Arya Reais-Parsi |
| Description | Inspired by: http://www.phpfront.com/php/Convert-Bytes-to-corresponding-size/?a=thanks
Converts number in bytes to the number in bytes, megabytes, gigabytes, terabytes, etc.
Works well as far as I can see! |
| Rating | (19 votes) |
PHP Code
function humanReadableOctets($octets)
{
$units = array('B', 'kB', 'MB', 'GB', 'TB'); // ...etc
for ($i = 0, $size =$octets; $size>1024; $size=$size/1024)
$i++;
return number_format($size, 2) . ' ' . $units[min($i, count($units) -1 )];
}
Comments
No comments posted yet.
|