totalusedMPFA2.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:18 2007 from totalusedMPFA2.php 2005/11/04 4.9 KB bytes.

<html>
<head>
<title>total used estimate</title>
</head>

<body bgcolor="#0066cc">

<h1 align="center">total used estimate</h1>

<?php 
$g_total = 0;
$g_count = 0;
$g_avail = (5000 * 1024 * 1024);
$g_missed = 0;
function getBlkSz( $sz ) {
   $blk = 4096;
   $bcnt = $sz / $blk;
   settype($bcnt,"int");
   if( $sz % $blk ) $bcnt++;
   if( $bcnt == 0 ) $bcnt++; // make zero a 1
   return ($bcnt * $blk);
}

function getSizeStr( $insz ) {
 $sz = getBlkSz( $insz );
 $ss = "$sz";
 if($sz < 1000) {
 $ss .= ' B';
 } elseif($sz < (1024*1024)) {
 $sk = ($sz / 1024) * 10;
 settype($sk,"int");
 $sk = $sk / 10;
 $ss = "$sk";
 $ss .= ' KB';
 } elseif($sz < (1024*1024*1024)) {
 $sk = ($sz / (1024*1024)) * 10;
 settype($sk,"int");
 $sk = $sk / 10;
 $ss = "$sk";
 $ss .= ' MB';
 } else {
 $sk = ($sz / (1024*1024*1024)) * 10;
 settype($sk,"int");
 $sk = $sk / 10;
 $ss = "$sk";
 $ss .= ' GB';
 }
 return $ss;
}

function getUsed ($dirName) {
   global $g_total, $g_count, $g_missed;
   $totused = 0;
   $d = dir($dirName);
   if (isset($d)) { // quietly, ignore failures, permissions wrong, etc
   while (false !== ($entry = $d->read())) {
   $locpath = $dirName.'/'.$entry;
   $size = filesize($locpath);
   $g_total += $size;
   $totused += getBlkSz($size);
   if ($entry != "." && $entry != "..") { 
   if (is_dir($locpath)) {
   if ($entry !== 'tmp') {
   $totused += getUsed ($locpath);
   }
   } else {
   $g_count++;
   }
   }
   }
   } else {
   $g_missed++;
   }
   return $totused;
}

function add_g_span2 ( $msg ) {
   return '<span style="background-color: #33ff33">'."\r\n".$msg."</span>\r\n";
}
function add_r_span2 ( $msg ) {
   return '<span style="background-color: #ff3333">'."\r\n".$msg."</span>\r\n";
}
function add_b_span2 ( $msg ) {
   return '<span style="background-color: #3333ff">'."\r\n".$msg."</span>\r\n";
}

$used = getUsed('.'); // get grand total, and set other public variable
$m_max = 100; // set a MAXIMUM character width ... and start HTML message ...
$imx = ($m_max * $used) / $g_avail; // get used fraction
settype($imx, "int"); // convert to an integer - whole number
$r_set = '*'; // set ONE, at least
if ($imx > $m_max) {
   $imx = $m_max; // set MAX
}
while($imx--) { // while we have a value, post decriment ...
   $r_set .= '*';
}
$g_set = '*';
if ($used < $g_avail) {
   $imx = ($m_max * ($g_avail-$used)) / $g_avail;
   settype($imx, "int");
   while($imx--) {
   $g_set .= '*';
   }
} else {
   // nothing
   $g_set = '';
}
$m_pct10 = (($used * 1000) / $g_avail);
settype($m_pct10, "int");
$m_eol = "\r\n";
$m_msg = '';

$m_msg .= "<center><table border=\"2\"><tr><td>".$m_eol;
$m_msg .= "<center><p>".$m_eol;
// top coloured line
$m_msg .= add_r_span2($r_set);
if (strlen( $g_set)) {
$m_msg .= add_g_span2($g_set);
}
$m_msg .= $m_eol;
$m_msg .= "<br>$m_eol";
$m_msg .= "estimates used total: $used (block) bytes (<b>" . ($m_pct10 / 10) . "%)</b><br>".$m_eol;
$a_msg = '|* Used <b>' . getSizeStr($used) . '</b> *|<br>'.$m_eol;
$a_msg .= "$r_set<br>".$m_eol;
$m_msg .= add_r_span2($a_msg);
if ($g_avail > $used) {
$a_msg = '|* Available <b>' . getSizeStr(($g_avail-$used)) . '</b> *|<br>'.$m_eol;
$a_msg .= "$g_set".$m_eol;
$m_msg .= add_g_span2($a_msg);
} else {
$a_msg = '|* Excess <b>' . getSizeStr(($used - $g_avail)) . '</b> *|<br>'.$m_eol;
$a_msg .= ' *** ALLOCATED SIZE EXCEEDED ***'.$m_eol;
$m_msg .= add_b_span2($a_msg);
}
$m_msg .= '<br>of ' . getSizeStr($g_avail);
$m_msg .= " ... (actual=$g_total, $g_count files.) ... <br>".$m_eol;
// bottom coloured line
$m_msg .= add_r_span2($r_set);
if ( strlen ($g_set) ) {
$m_msg .= add_g_span2($g_set);
}
// close paragraph
$m_msg .= '</p></center>'.$m_eol;
// close table
$m_msg .= '</td></tr>'.$m_eol;
$m_msg .= '</table></center>'.$m_eol;

print "$m_msg\r\n";

?>

<p>Note: This is an estimate only, using a 'block' size of 4096 bytes ... in most 
operating systems, the hard disk space is divided up into blocks, sometimes called 
'sectors' ... that means, even a file of just a few bytes in length, takes a minimum of one 
sector, or block ... while its file size will remain only a few bytes, it will occupy one, 
or more, complete sector, block, on the disk ... and then there are the directory enries 
themselves ... in this estimate, assumed to take one block ...</p>

<p>Also each file occupies some bytes for the file name, as a directory 
entry ... and space for the names of the directories, the folders, on the disk ... but these 
extra bytes for the directory entries are not usually counted ...</p>

<center>
<span style="background-color: #FFFFFF">
<p>|* <a href="index.html">index</a> *|</p>
</span>
</center>

</body>
</html>
<!-- totalused.php - fixed for NEGATIVE -- ie excess useage - 13 August 2005 - macpcfirstaid.com - grm -->
<!-- totalused.php - simple estimate of site useage - created 8 August 2005 - macpcfirstaid.com - grm -->

index

Valid HTML 4.01 Transitional