Human Readable filesize


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.