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


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.