Posted By

luman on 07/16/09


Tagged

file size bytes


Versions (?)

formatBytes


 / Published in: PHP
 

URL: http://net.tutsplus.com/tutorials/php/online-file-storage-with-php/

  1. function formatBytes($bytes, $precision = 2) {
  2. $units = array('B', 'KB', 'MB', 'GB', 'TB');
  3.  
  4. $bytes = max($bytes, 0);
  5. $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
  6. $pow = min($pow, count($units) - 1);
  7.  
  8. $bytes /= pow(1024, $pow);
  9.  
  10. return round($bytes, $precision) . ' ' . $units[$pow];
  11. }

Report this snippet  

You need to login to post a comment.