Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/articles/php-tutorials/)
-   -   Filesize formatting function (http://www.go4expert.com/articles/filesize-formatting-function-t1298/)

pradeep 29Aug2006 21:32

Filesize formatting function
 
Here's a function which will format the passed bytes into KB,MB,GB...appropriately.

Code: PHP

function GetSize ($sizeb) {
   $sizekb = $sizeb / 1024;
   $sizemb = $sizekb / 1024;
   $sizegb = $sizemb / 1024;
   $sizetb = $sizegb / 1024;
   $sizepb = $sizetb / 1024;
   if ($sizeb > 1) {$size = round($sizeb,2) . "b";}
   if ($sizekb > 1) {$size = round($sizekb,2) . "kb";}
   if ($sizemb > 1) {$size = round($sizemb,2) . "mb";}
   if ($sizegb > 1) {$size = round($sizegb,2) . "gb";}
   if ($sizetb > 1) {$size = round($sizetb,2) . "tb";}
   if ($sizepb > 1) {$size = round($sizepb,2) . "pb";}
   return $size;
 }



All times are GMT +5.5. The time now is 05:56.