I've successfully created a script that will display the disk space usage of my domain...however I want to take it a step further and take that data to create a percentage bar in java that will show the percentage of the disk space used in regards to a certain number of MB's my account allots me for my hosting account:
Here is what I have so far..but the bar doesnt show...look at my last line
<?php
function getDirectorySize($path)
{
$totalsize = 0;
$totalcount = 0;
$dircount = 0;
if ($handle = opendir ($path))
{
while (false !== ($file = readdir($handle)))
{
$nextpath = $path . '/' . $file;
if ($file != '.' && $file != '..' && !is_link ($nextpath))
{
if (is_dir ($nextpath))
{
$dircount++;
$result = getDirectorySize($nextpath);
$totalsize += $result['size'];
$totalcount += $result['count'];
$dircount += $result['dircount'];
}
elseif (is_file ($nextpath))
{
$totalsize += filesize ($nextpath);
$totalcount++;
}
}
}
}
closedir ($handle);
$total['size'] = $totalsize;
$total['count'] = $totalcount;
$total['dircount'] = $dircount;
return $total;
}
function sizeFormat($size)
{
if($size<1024)
{
return $size." bytes";
}
else if($size<(1024*1024))
{
$size=round($size/1024,1);
return $size." KB";
}
else if($size<(1024*1024*1024))
{
$size=round($size/(1024*1024),1);
return $size." MB";
}
else
{
$size=round($size/(1024*1024*1024),1);
return $size." GB";
}
}
$path= $glob['rootDir'];
$ar=getDirectorySize($path);
echo "<h4>Diskspace Usage $path</h4>";
echo ":".sizeFormat($ar['size'])." of 1000MB<br>";
?>
<style type="text/css">
div.smallish-progress-wrapper {
position: relative;
border: 1px solid black;
}
div.smallish-progress-bar {
position: absolute;
top: 0;
left: 0;
height: 100%;
}
div.smallish-progress-text {
text-align: center;
position: relative;
}
</style>
<script type="text/javascript">
function drawProgressBar(color, width, percent) {
var pixels = width * (percent / 1000);
document.write('<div class="smallish-progress-wrapper" style="width: ' + width + 'px">'); document.write('<div class="smallish-progress-bar" style="width: ' + pixels + 'px; background-color: ' + color + ';"></div>'); document.write('<div class="smallish-progress-text" style="width: ' + width + 'px">' + percent + 'MB</div>'); document.write('</div>'); } </script>
<script type="text/javascript">drawProgressBar('#987654', 500, <?php echo " ".sizeFormat($ar['size'])." of 1000MB"; ?>);</script>