$path = '5.txt';
(int)$size = filesize($path);
switch ($size) {
case $size >= 1073741824:
$size = round($size / 1073741824 * 100) / 100 . ' GB';
break;
case $size >= 1048576:
$size = round($size / 1048576 * 100) / 100 . ' MB';
break;
case $size >= 1024:
$size = round($size / 1024 * 100) / 100 . ' KB';
break;
default:
$size .= ' Bytes';
break;
}