PHP Front
The PHP website created by its users!
Home » PHP » human readable byte format


human readable byte format


AuthorArya Reais-Parsi
DescriptionInspired 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!
RatingThis script has been rated 4/5 (13 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 )];
    }



Rate it: Print Print

Comments


No comments posted yet.

Name
Website
Your comment