|
[Edit] Convert octets to Ko, Mo, Go
When displaying a filesize, it is way much nicer to display “1 Mo” instead of “1048576 octets”. This very handy code snippet take a filesize in octets as a parameter, and will return the filesize converted to Ko, Mo or Go.
UsageSimply call the function with your filesize as a parameter:echo GetSizeName(21354685545); function GetSizeName($octet){
$unite = array(' octet',' Ko',' Mo',' Go');
if ($octet < 1000) {
return $octet.$unite[0];
} else {
if ($octet < 1000000) {
$ko = round($octet/1024,2);
return $ko.$unite[1];
} else {
if ($octet < 1000000000) {
$mo = round($octet/(1024*1024),2);
return $mo.$unite[2];
} else {
$go = round($octet/(1024*1024*1024),2);
return $go.$unite[3];
}
}
}
}
|
This Page is Under Construction! - If You Want To Help Please Send your CV - Advanced Web Core (BETA)
© Advanced Web Core. All rights reserved

