function download_file_format_bytes in DownloadFile 7
Same name and namespace in other branches
- 6 download_file.module \download_file_format_bytes()
- 7.3 download_file.module \download_file_format_bytes()
- 7.2 download_file.module \download_file_format_bytes()
Converts human readable file size (e.g. 10 MB, 200.20 GB) into bytes.
Parameters
$bytes: File size in bytes.
$precision: The precision after the decimal.
Return value
An array containing the formatted size and the unit.
1 call to download_file_format_bytes()
- theme_download_file_bytes_accessible in ./
download_file.formatter.inc - Theme function for the size format accessible.
File
- ./
download_file.module, line 264 - Module to direct download files or images.
Code
function download_file_format_bytes($bytes, $precision) {
$units = array(
t('B'),
t('KB'),
t('MB'),
t('GB'),
t('TB'),
t('PB'),
);
$pow = floor(log($bytes) / log(1024));
$output = sprintf('%.' . $precision . 'f ', $bytes / pow(1024, floor($pow)));
return array(
$output,
$units[$pow],
);
}