function HumanSize($Bytes)
{
$Type=array("", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta");
$Index=0;
while($Bytes>=1024)
{
$Bytes/=1024;
$Index++;
}
return("".$Bytes." ".$Type[$Index]."bytes");
}
echo HumanSize(33535356576765656766656445456);
?>
Monday, 27 July 2009
To get the alphabets in Loop function
for ($i = 65; $i <= 90; $i++)
{
echo $drive = chr($i);
}
OUTPUT:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
{
echo $drive = chr($i);
}
OUTPUT:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
To get the disk space of your system using php
for ($i = 67; $i <= 90; $i++)
{
$drive = chr($i);
if (is_dir($drive.':'))
{
$freespace = disk_free_space($drive.':');
$total_space = disk_total_space($drive.':');
$percentage_free = $freespace ? round($freespace / $total_space, 2) * 100 : 0;
echo $drive.': '.to_readble_size($freespace).' / '.to_readble_size($total_space).' ['.$percentage_free.'%]
';
}
}
function to_readble_size($size)
{
switch (true)
{
case ($size > 1000000000000):
$size /= 1000000000000;
$suffix = 'TB';
break;
case ($size > 1000000000):
$size /= 1000000000;
$suffix = 'GB';
break;
case ($size > 1000000):
$size /= 1000000;
$suffix = 'MB';
break;
case ($size > 1000):
$size /= 1000;
$suffix = 'KB';
break;
default:
$suffix = 'B';
}
return round($size, 2).$suffix;
}
?>
Subscribe to:
Posts (Atom)