[PHP]Function file size

Download | Vote Up (0) | Vote Down (0)
<?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;
                }
}
?>

Zhyar


Be the first to give feedback !

Please login to comment !