Posted By

zhyar on 10/01/12


Tagged

php format function size


Versions (?)

Size format function


 / Published in: PHP
 

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

  1. <?php
  2. /* Use : echo format_size(filesize("fichier"));
  3. Example result : 13,37 Ko */
  4.  
  5. function format_size($o) {
  6. $size = array('Go' => 1073741824, 'Mo' => 1048576, 'Ko' => 1024, 'octets' => 1);
  7. foreach ($size as $k => $v)
  8. if ($o >= $v) {
  9. if ($k == 'octets')
  10. return round($o).' '.$k;
  11. return number_format($o / $v, 2, ',', ' ').' '.$k;
  12. }
  13. }
  14. ?>

Report this snippet  

You need to login to post a comment.