<?php
function byte_to_str($size) {
$units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
$current = 0;
$currentSize = $size;
while ($currentSize >= 1024 && $current < sizeof($units) - 1) {
$current++;
$currentSize /= 1024;
}
return number_format($currentSize, ($current == 0) ? 0 : 2).' '.$units[$current];
}