По 2 вопросу
function fncFileSizeInBytes2HumanString($FileSizeInBytes) {
/*
To-Do: 1) float input value 2) giga
Compatibility: PHP >= 4.0.1
*/
$intvalFileSizeInBytes = intval($FileSizeInBytes);
if ( ! is_int($FileSizeInBytes) ) {
if ( is_string($FileSizeInBytes) && $FileSizeInBytes === strval($intvalFileSizeInBytes) ) {
trigger_error(\'[parameter type conversion]\', E_USER_NOTICE);
} # if
else {
trigger_error(\'[incorrect type of parameter]\', E_USER_WARNING);
return FALSE;
} # else
} # if
if ( $intvalFileSizeInBytes < 0 ) {
trigger_error(\'[negative value of parameter]\', E_USER_WARNING);
return FALSE;
} # if
else {
if ( $intvalFileSizeInBytes < 1024 ) {
return $intvalFileSizeInBytes . \' b\';
} # if
$floatFileSizeInKilobytes = $intvalFileSizeInBytes / 1024;
$roundfloatFileSizeInKilobytes = round($floatFileSizeInKilobytes, 1);
if ( $roundfloatFileSizeInKilobytes < 1024 ) {
return ( $roundfloatFileSizeInKilobytes != $floatFileSizeInKilobytes ? \'~\' : \'\' ) . $roundfloatFileSizeInKilobytes . \' Kb\';
} # if
$floatFileSizeInMegabytes = $intvalFileSizeInBytes / 1048576;
$roundfloatFileSizeInMegabytes = round($floatFileSizeInMegabytes, 2);
return ( $roundfloatFileSizeInMegabytes != $floatFileSizeInMegabytes ? \'~\' : \'\' ) . $roundfloatFileSizeInMegabytes . \' Mb\';
} # else
} # function