• Welcome to the Chevereto User Community!

    Here, users from all over the world come together to learn, share, and collaborate on everything related to Chevereto. It's a place to exchange ideas, ask questions, and help improve the software.

    Please keep in mind:

    • This community is user-driven. Always be polite and respectful to others.
    • Support development by purchasing a Chevereto license, which also gives you priority support.
    • Go further by joining the Community Subscription for even faster response times and to help sustain this space

Image Directory Informations

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:
c7z20.png


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