Convert bytes to human readable format (KB, MB, GB, etc.) for file sizes.
Code
Utilities$units = ['B', 'KB', 'MB', 'GB', 'TB'];
$i = 0;
$size = $bytes;
while ($size >= 1024 && $i < count($units) - 1) { $size /= 1024; $i++; }
return sprintf("%.2f %s", $size, $units[$i]);Parameters
Number of bytes.
Server
More PHP Snippets
Binary to Decimal
Convert a binary string representation to its decimal number equivalent.
Calculate Median
Calculate the median value of an array of numbers.
Calculate Mode
Find the most frequent value(s) in an array.
Calculate Percentile
Calculate the nth percentile of an array using linear interpolation.
Celsius to Fahrenheit
Convert temperature from Celsius to Fahrenheit using the standard formula.
Clamp Number
Restrict a number to be within a minimum and maximum range.