Here's a simple function that will convert the shorthand values described in point 64.16 to a number of bytes.
I use this to display the maximum size of file uploads to the user, so they don't waste time uploading a huge file only to find that it's too big. (I've been unable to find any browsers that actually support the MAX_FILE_SIZE technique described in chapter 38, and it's certainly not part of any W3C spec, so this is the next best thing.)
Here's how you'd use my function for that purpose (though you might want to abstract this to a function of its own):
<?php
echo 'Maximum file size: ' . convertBytes( ini_get( 'upload_max_filesize' ) ) / 1048576 . 'MB';
?>
And here's the function:
<?php
function convertBytes( $value ) {
if ( is_numeric( $value ) ) {
return $value;
} else {
$value_length = strlen( $value );
$qty = substr( $value, 0, $value_length - 1 );
$unit = strtolower( substr( $value, $value_length - 1 ) );
switch ( $unit ) {
case 'k':
$qty *= 1024;
break;
case 'm':
$qty *= 1048576;
break;
case 'g':
$qty *= 1073741824;
break;
}
return $qty;
}
}
?>