PHP: Human readable filesize

Here is minimal from code what I saw ever to convert long number of bytes into the human readable format.

<?php // New php styled function hrFilesize($number, $base=1024) { $pow=floor(log($number)/log($base)); return number_format($number/pow($base, $pow), 2) . ['b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb'][$pow]; } ?>

Leave a Reply

Your email address will not be published. Required fields are marked *