Topic: Image Directory Informations

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:
http://chevereto.com/2.0/images/c7z20.png

ENGINE.PHP

find

<?

add AFTER

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

$allow_over_resize = false; // true: Allows over resize images - false: Don't allow over resize.

add AFTER

$information = getDirectorySize(DIR_IM);

INDEX.PHP

find

<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

<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>

Last edited by Danny.Domb (2011-05-25 15:35:11)

~ Sup?!

Thumbs up +1

Re: Image Directory Informations

Thanks! smile

Thumbs up

Re: Image Directory Informations

Fucking amazing!

Thumbs up

Re: Image Directory Informations

where is engine.php ?

Thumbs up

Re: Image Directory Informations

this mod is for version 1.9. Lycoss you are using 2.0

~ Sup?!

Thumbs up