The size of the php statistics file, which is measured in GB, MB, KB, and B. Use the filesize () function command to calculate the file size. the value 1 must be an output of GB, MB, KB, and B. 2. the order of magnitude must be greater than 1 and less than 1024, and two decimal places must be retained. use the filesize () function command to calculate the file size. requirements: 1, it is an output in GB, MB, KB, and B. 2. the order of magnitude must be greater than 1 and less than 1024, and two decimal places must be retained; 
Start: 
 
 The code is as follows:
 
 
$ Len = filesize ("1. rmvb ");
$ I = 4;
While ($ I ){
If ($ out = $ len/pow (1024, $ I)> 1.0 | $ I = 1 ){
Switch ($ I ){
Case 4: {printf ("%. 2f TB", $ out); break ;}
Case 3: {printf ("%. 2f GB", $ out); break ;}
Case 2: {printf ("%. 2f MB", $ out); break ;}
Case 1: {printf ("%. 2f KB", $ out); break ;}
}
Break;
}
$ I --;
}
 
Demo effect: 
View sourceprint? 1.85 GB 
2.70 GB 
We are proud to find a simpler and more effective method (So Peifu) on the PHP Tutorial on the PHP official website) 
The code is as follows: 
 
 The code is as follows:
 
 
Function format_bytes ($ size ){
$ Units = array ('B', 'KB', 'mb', 'GB', 'TB ');
For ($ I = 0; $ size >=1024 & $ I <4; $ I ++) $ size/= 1024;
Return round ($ size, 2). $ units [$ I];
}
 
Demo effect: 
1.85 GB 
2.7 GB 
Of course there are more practices, but this method should be the simplest and fastest. I believe you have other methods. I look forward to sharing them with you! 
 
 
The Compile () function command is used to calculate the file size. the value 1 must be an output of GB, MB, KB, and B. 2. the order of magnitude must be greater than 1 and less than 1024, and two decimal places must be retained; start...