Danny.Domb
👽 Chevereto Freak
Here is 2 little functions to retreive the number of file, the size of and the number of sub directories in the DIR_IM (images/) directory.
Demo:
ENGINE.PHP
find
add AFTER
CONFIG.PHP
find
add AFTER
INDEX.PHP
find
REPLACE WITH
Demo:
ENGINE.PHP
find
Code:
<?
add AFTER
Code:
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)
{
$return = '';
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";
}
return $return;
}
CONFIG.PHP
find
Code:
$allow_over_resize = false; // true: Allows over resize images - false: Don't allow over resize.
add AFTER
Code:
$information = getDirectorySize(DIR_IM);
INDEX.PHP
find
Code:
<div id="foot"><div class="foot-d2"><?php echo APP_NAME;?>, Powered by <a href="http://chevereto.com/" target="_blank">Chevereto</a></div></div>
REPLACE WITH
Code:
<div id="foot">
<div class="foot-d2">
Total directory size : <?php echo sizeFormat($information['size']); ?><br />
Number of files : <?php echo $information['count']; ?><br />
Number of sub-directories : <?php echo $information['dircount']; ?><br />
<?php echo APP_NAME; ?>, Powered by <a href="http://chevereto.com/" target="_blank">Chevereto</a>
</div>
</div>