Posted By

ReeceMarsland on 02/17/10


Tagged

php files


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

dantreacy
IMPGTX


Calculate file size with range i.e bytes, kb, mb, gb


 / Published in: PHP
 

  1. function get_file_size($file_size) {
  2. $range = 0;
  3.  
  4. $size[0] = 'bytes';
  5. $size[1] = 'kb';
  6. $size[2] = 'mb';
  7. $size[4] = 'gb';
  8. $size[5] = 'tb';
  9.  
  10. while($file_size>1024){
  11. $file_size = $file_size / 1024;
  12. $range++;
  13. }
  14.  
  15. $file_size = round($file_size, 2);
  16. return $file_size.' '.$size[$range];
  17. }

Report this snippet  

You need to login to post a comment.