//Convert bytes to higer values
function byteConvert($INPUT)
{
$temp = $INPUT;
//If it's over a Gigabyte
if ($temp >= 1024000000){
$temp = $temp / 1024000000;
$temp = round($temp,2);
$temp = $temp . " " . "Gb";
return $temp;
}
//If it's over a Megabyte
elseif ($temp >=1024000){
$temp = $temp / 1024000;
$temp = round($temp,2);
$temp = $temp . " " . "Mb";
return $temp;
}
//If' it's over a kilobyte
elseif ($temp >=1024){
$temp = $temp / 1024;
$temp = round($temp,2);
$temp = $temp . " " . "Kb";
return $temp;
}
//If' it's under a kilobyte
else
$temp = round($temp,2);
$temp = $temp . " " . "b";
return $temp;
}
?>
EnjoyThe musing and sometimes not so wise words of Jonathan Dalrymple, Global Traveller, Programmer, Financial Rocket Scientist, Conspiracy Theorist, Part-time comedian, full-time funny man and whatever else i randomly decide to do.
Friday, September 01, 2006
Code Snippets
Having learnt PHP like yesterday, i decided that i might most some of my code. This function converts file sizes to user friendly Gigabytes, Megabytes, or Kilobytes.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment