byte_to_str (listed) 13.09.2019 18:23:27 (11 lines) [Edit] [Raw] [View]

<?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]; }