Using the FileSize () function command to achieve file size statistics, requires: 1, in GB, MB, KB, b in one output; 2. The order of magnitude must be greater than 1 and less than 1024, and two decimal places are reserved;
Commenced construction:
Copy the Code code as follows:
$len = FileSize ("1.RMVB");
$i = 4;
while ($i) {
if ($out = $len/pow (1024x768, $i)) >1.0| | $i ==1) {
Switch ($i) {
Case 4: {printf ("%.2f TB", $out);
Case 3: {printf ("%.2f GB", $out);
Case 2: {printf ("%.2f MB", $out);
Case 1: {printf ("%.2f KB", $out);
}
Break
}
$i--;
}
Demo Effect:
View SOURCEPRINT?1.85GB
2.70GB
Proud room, on the PHP website PHP tutorial See, the results found a simpler and more effective method (so Peifu)
The code is as follows:
Copy the Code code as follows:
function Format_bytes ($size) {
$units = Array (' B ', ' KB ', ' MB ', ' GB ', ' TB ');
for ($i = 0; $size >= && $i < 4; $i + +) $size/= 1024;
Return round ($size, 2). $units [$i];
}
Demo Effect:
1.85GB
2.7GB
Of course there are more ways, but this method is the simplest, the fastest, I believe you have other ways, look forward to your sharing!
The above describes the Mission Impossible 4 PHP statistical file size, in GB, MB, KB, b output, including the Mission Impossible 4 aspects of the content, I hope that the PHP tutorial interested in a friend helpful.