acf_format_filesize()
acf_format_filesize
This function will return a formatted string containing the filesize and unit
No Hooks.
Returns
(Int).
Usage
acf_format_filesize( $size );
- $size
- .
Default:1
Changelog
| Since 5.1.5 | Introduced. |
acf_format_filesize() acf format filesize code ACF 6.8.8
function acf_format_filesize( $size = 1 ) {
// convert
$bytes = acf_get_filesize( $size );
// vars
$units = array(
'TB' => 4,
'GB' => 3,
'MB' => 2,
'KB' => 1,
);
// loop through units
foreach ( $units as $k => $v ) {
$result = $bytes / pow( 1024, $v );
if ( $result >= 1 ) {
return $result . ' ' . $k;
}
}
// return
return $bytes . ' B';
}