1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Filesize formatting function

Discussion in 'PHP' started by pradeep, Aug 29, 2006.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Here's a function which will format the passed bytes into KB,MB,GB...appropriately.

    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;
     }
     

Share This Page