<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<!-- THIS STYLE PERTAINS TO THE BAR GRAPH IMAGES... ITS CSS, ONE OVER THE OTHER -->
<style type="text/css">
img.percentImage {
background: white url(percentImage_back.png) top left no-repeat;
padding: 0;
margin: 5px 0 0 0;
background-position: 1px 0;
}
</style>
</head>
<body>
<?php
define ("DISK","/home/YOURDIRECTORY/"); //DIRECTORY WITH PERMISSIONS
if (!($_POST["maxvalue"])) //JUST AN IF FOR THE FORM INPUT
{
define ("SPACE","1048576"); //IN KB MAX SIZE ( USE ONLY THIS LINE FOR REAL PURPOSES )
}
else
{
if (is_numeric ($_POST["maxvalue"]))
{
define ("SPACE",$_POST["maxvalue"]);
}
else
{
define ("SPACE","1048576"); //IN KB MAX SIZE
echo "<script>alert('Try to use numbers');</script>"; //POPUP FOR TEXT INPUTS
}
}
function CountDir($aDir, $aRecurse) //HUGE LOOPS TO RUN THROUGH FOLDERS AND FILES
{
$d = dir($aDir);
while ($Entry = $d->Read())
{
if (!(($Entry == "..") || ($Entry == ".")))
{
if (Is_Dir($aDir . '/' . $Entry))
{
if ($aRecurse)
{
$FinalValue += CountDir($aDir . '/' . $Entry, $aRecurse);
}
}
else
{
$FinalValue += round((filesize($aDir . '/' . $Entry))/1024, 2); //WHERE THE REAL MATH GOES DOWN
}
}
}
return $FinalValue;
}
$du = CountDir(DISK, True);
//$df = round(disk_free_space(DISK)/1024/1024, 2); //OLD METHOD FOR WHOLE PARTITION
//$dt = round(disk_total_space(DISK)/1024/1024, 2);
$dt = SPACE;
$df = $dt-$du;
$percf = $df/$dt*100;
$percu = $du/$dt*100;
$outp = round(($percf/100*122)+1, 2); //SOME COOL MATH, 122 because its the size of the bar image
?>
<img src="percentImage.png" alt="<? echo round("$percu", 2); ?>%" class="percentImage" style="background-position: -<? echo "$outp"; ?>px 0pt;"/><!-- inputing the position of the bar and also the ALT test as the percent -->
<!-- ALL DEBUGS, USE HOW YOU LIKE -->
<br /><? echo round("$percu", 2); ?>% disk perc used
<br /><? echo round("$du"/1024, 2); ?> disk used megs
<br /><? echo round("$percf", 2); ?>% disk perc free
<br /><? echo round("$df"/1024, 2); ?> disk free megs
<br /><? echo round("$dt"/1024, 2); ?> disk total megs
<br /><br />
<form method="post" action="test.php"><!-- My form for value change -->
Change Max Space:<br />
<input type="text" name="maxvalue">KB
<br /><input type="submit" value="Change It!">
</form>
</body>
</html>
<!-- CREDS NOTHINGNESS, PM FOR CUSTOMIZATIONS -->