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.


//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;
}
?>
Enjoy

No comments: