For a non-looping way to add symbols to a number of bytes:
<?php
function getSymbolByQuantity($bytes) {
$symbols = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
$exp = floor(log($bytes)/log(1024));
return sprintf('%.2f '.$symbol[$exp], ($bytes/pow(1024, floor($exp))));
}