Return to Snippet

Revision: 59789
at October 1, 2012 21:37 by zhyar


Initial Code
<?php
/* Use : echo format_size(filesize("fichier"));
Example result : 13,37 Ko */
 
function format_size($o) {
    $size = array('Go' => 1073741824, 'Mo' => 1048576, 'Ko' => 1024, 'octets' => 1);
    foreach ($size as $k => $v)
        if ($o >= $v) {
                if ($k == 'octets')
                        return round($o).' '.$k;
                return number_format($o / $v, 2, ',', ' ').' '.$k;
        }
}
?>

Initial URL

                                

Initial Description
Use: echo format_size(filesize("fichier"));
Example result: 13,37 Ko

Initial Title
Size format function

Initial Tags
php, format, function

Initial Language
PHP