formatFileSize.php
Table of Contents
Functions
- formatFileSize() : string
- Formats a byte count as a human-readable string.
Functions
formatFileSize()
Formats a byte count as a human-readable string.
formatFileSize(int $bytes[, int $precision = 2 ]) : string
Uses binary multiples (base 1024) with the FileSizeUnit symbols B, KB, MB, GB, TB, PB.
Byte values are rendered without decimals; larger units use $precision decimals.
Zero or negative values yield "0 B". Values beyond PB are clamped to PB.
Parameters
- $bytes : int
-
The size in bytes (e.g. from getFileSize()).
- $precision : int = 2
-
Number of decimals for non-byte units (default:
2).
Tags
Return values
string —A human-readable size, e.g. "1.18 MB".