totalusedGMCOM.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:18 2007 from totalusedGMCOM.php 2005/08/09 4.6 KB bytes.

<html>
<head>
<title>total used estimate - geoffmclane.com</title>
</head>

<body bgcolor="#0066cc">

<h1 align="center">total used estimate - geoffmclane.com</h1>

<?php 
$g_total = 0;
$g_count = 0;
$g_avail = (500 * 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;
}

$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 = '*';
while($imx--) { // while we have a value, post decriment ...
   $r_set .= '*';
}
$imx = ($m_max * ($g_avail-$used)) / $g_avail;
settype($imx, "int");
$g_set = '*';
while($imx--) {
   $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 .= '<span style="background-color: #ff3333">';
$m_msg .= $r_set;
$m_msg .= '</span>';
$m_msg .= '<span style="background-color: #33ff33">';
$m_msg .= $g_set;
$m_msg .= '</span><br>'.$m_eol;
$m_msg .= "estimates used total: $used (block) bytes (<b>" . ($m_pct10 / 10) . "%)</b><br>".$m_eol;
$m_msg .= '<span style="background-color: #ff3333">'.$m_eol;
$m_msg .= '|* Used <b>' . getSizeStr($used) . '</b> *|<br>'.$m_eol;
$m_msg .= "$r_set<br>".$m_eol;
$m_msg .= '</span>'.$m_eol;
$m_msg .= '<span style="background-color: #33ff33">'.$m_eol;
$m_msg .= '|* Available <b>' . getSizeStr(($g_avail-$used)) . '</b> *|<br>'.$m_eol;
$m_msg .= "$g_set<br>".$m_eol;
$m_msg .= '</span>'.$m_eol;
$m_msg .= 'of ' . getSizeStr($g_avail);
$m_msg .= " ... (actual=$g_total, $g_count files.) ... <br>".$m_eol;
// bottom coloured line
$m_msg .= '<span style="background-color: #ff3333">';
$m_msg .= $r_set;
$m_msg .= '</span>';
$m_msg .= '<span style="background-color: #33ff33">';
$m_msg .= $g_set;
$m_msg .= '</span>'.$m_eol;
// 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> *|* <a href="http://macpcfirstaid.com">macpcfirstaid.com</a> *|</p>
</span>
</center>

</body>
</html>
<!-- totalused.php - simple estimate of site useage - 9 August 2005 - geoffmclane.com - grm -->
<!-- totalused.php - MPFA - macpcfirstaid.com - grm -->
<!-- totalused.php - FOF - www.friendofflowers.com - grm -->

index

Valid HTML 4.01 Transitional