acf_get_filesize()
acf_get_filesize
This function will return a numeric value of bytes for a given filesize string
No Hooks.
Returns
(Int).
Usage
acf_get_filesize( $size );
- $size
- .
Default:1
Changelog
| Since 5.1.5 | Introduced. |
acf_get_filesize() acf get filesize code ACF 6.8.8
function acf_get_filesize( $size = 1 ) {
// vars
$unit = 'MB';
$units = array(
'TB' => 4,
'GB' => 3,
'MB' => 2,
'KB' => 1,
);
// look for $unit within the $size parameter (123 KB)
if ( is_string( $size ) ) {
// vars
$custom = strtoupper( substr( $size, -2 ) );
foreach ( $units as $k => $v ) {
if ( $custom === $k ) {
$unit = $k;
$size = substr( $size, 0, -2 );
}
}
}
// calc bytes
$bytes = floatval( $size ) * pow( 1024, $units[ $unit ] );
// return
return $bytes;
}