Advertisement
zefie

Future-proof (for a good while) byte size to string function

Aug 17th, 2018
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. function friendlyBytes($size,$pre = 2) {
  2.         $sizes = array('B','KB','MB','GB','TB','PB','EB','ZB','YB');
  3.         for ($i = (count($sizes)); $i > 0; $i--) {
  4.                 if ($i > 0) {
  5.                         $exp = pow(1024,$i);
  6.                         if ($size > $exp) {
  7.                                 return round(($size / $exp),$pre).$sizes[$i];
  8.                         }
  9.                 }
  10.         }
  11.         return $size."B";
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement