Posted By

gbot on 03/26/08


Tagged

filesize


Versions (?)

Who likes this?

11 people have marked this snippet as a favorite

gbot
mb
SpinZ
tcmacdonald
JimiJay
juke
robe
Slashman
josex
ikimozu
ringo380


Human Readable filesize


 / Published in: PHP
 

  1. function ByteSize ( $file_size )
  2. {
  3. $file_size = $file_size-1;
  4. if ($file_size >= 1099511627776) $show_filesize = number_format(($file_size / 1099511627776),2) . " TB";
  5. elseif ($file_size >= 1073741824) $show_filesize = number_format(($file_size / 1073741824),2) . " GB";
  6. elseif ($file_size >= 1048576) $show_filesize = number_format(($file_size / 1048576),2) . " MB";
  7. elseif ($file_size >= 1024) $show_filesize = number_format(($file_size / 1024),2) . " KB";
  8. elseif ($file_size > 0) $show_filesize = $file_size . " b";
  9. elseif ($file_size == 0 || $file_size == -1) $show_filesize = "0 b";
  10. return $show_filesize;
  11. }

Report this snippet  

You need to login to post a comment.