Size format function


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.