Posted By

cochambre on 06/30/06


Tagged

file style String windows size


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

luman
nicolaspar


Devuelve un string indicando del tamaño de un archivo al estilo Windows.


 / Published in: PHP
 

  1. function getFileSize($bytes) {
  2. if ($bytes >= 1099511627776) {
  3. $return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
  4. $suffix = "TB";
  5. } elseif ($bytes >= 1073741824) {
  6. $return = round($bytes / 1024 / 1024 / 1024, 2);
  7. $suffix = "GB";
  8. } elseif ($bytes >= 1048576) {
  9. $return = round($bytes / 1024 / 1024, 2);
  10. $suffix = "MB";
  11. } elseif ($bytes >= 1024) {
  12. $return = round($bytes / 1024, 2);
  13. $suffix = "KB";
  14. } else {
  15. $return = $bytes;
  16. $suffix = "Bytes";
  17. }
  18. if ($return == 1) {
  19. $return .= " " . $suffix;
  20. } else {
  21. $return .= " " . $suffix . " ";
  22. }
  23. return $return;
  24. }

Report this snippet  

You need to login to post a comment.