Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Конвертор байт в KB, MB, GB или TB.
- * @param int $bytes Байты
- * @param string $unit Еденица измерения: B, KB, MB, GB или TB, или false, если не надо форматировать измерение
- * @param int $precision точность
- * @return float
- */
- public static function formatBytes($bytes, $unit = 'KB', $precision = 2)
- {
- if ($unit === false) {
- return $bytes;
- }
- $unit = strtoupper($unit);
- $unitPow = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4);
- $bytes /= pow(1024, $unitPow[$unit]);
- return round($bytes, $precision);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement