Convert the file size to a user-friendly way, that is, display as "xxxgb", "xxxmb.
PHPCodeAs follows:
Function My_formatsize ( $ Size ){ $ Size = Doubleval ( $ Size ); $ Rank = 0 ; $ Rankchar = 'Bytes' ; While ($ Size > 1024 ){ $ Size = $ Size /1024 ; $ Rank ++ ;} If ( $ Rank = 1 ){ $ Rankchar = "Kb" ;} Else If ($ Rank = 2 ){ $ Rankchar = "MB" ;} Else If ( $ Rank = 3 ){ $ Rankchar = "GB" ;} $ Size = Number_format ( $ Size , 2 ,'.','' ); Return "". $ Size ."". $ Rankchar ;}
The javascript code is as follows:
Function My_formatsize ($ size ){ VaR Size = Parsefloat ($ size ); VaR Rank = 0 ; VaR Rankchar = 'bytes' ; While (Size> 1024) {Size = Size/1024; Rank ++ ;} If (Rank = 1 ) {Rankchar = "Kb" ;} Else If (Rank = 2 ) {Rankchar = "MB" ;} Else If (Rank = 3 ) {Rankchar = "GB" ;} Return Size. tofixed (2) + "" + Rankchar ;}
Keep two decimal places in the code.