How to round file size

Discussion in 'PHP' started by Kuna, Jan 5, 2010.

  1. #1
    this is how I show size of uploaded file

    echo "<strong>File Size: </strong><br>".$HTTP_POST_FILES['ufile']['size']." bytes<BR/>"
    .$HTTP_POST_FILES['ufile']['size']/1024 . ' Kb<BR/>'
    .$HTTP_POST_FILES['ufile']['size']/(1024*1024) . ' Mb<BR/><BR/>'
    
    ;
    
    PHP:
    how to round size of kb and mb?
     
    Kuna, Jan 5, 2010 IP
  2. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #2
    should be:
    
    echo "<strong>File Size: </strong><br>".$HTTP_POST_FILES['ufile']['size']." bytes<BR/>"
    .round($HTTP_POST_FILES['ufile']['size']/1024) . ' Kb<BR/>'
    .round($HTTP_POST_FILES['ufile']['size']/(1024*1024)) . ' Mb<BR/><BR/>'
    
    ;
    
    
    PHP:
    note this just strips the decimals.. if you want to round up or down checkout ceil() at http://se2.php.net/manual/en/function.ceil.php or floor() at http://se2.php.net/manual/en/function.floor.php
     
    n3r0x, Jan 5, 2010 IP
  3. Kuna

    Kuna Well-Known Member

    Messages:
    426
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    thanks a lot
     
    Kuna, Jan 5, 2010 IP