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


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.