Page 1 of 1

Help getting correct file count using count(glob(

Posted: Sat Jan 31, 2009 8:27 pm
by imagewiz
I am using the following code to return file count in directories, (and subdirectories) but the code returns 0 until 2 files are found. If I change if ($total_files_home <= 1) to if ($total_files_home <= 0) or if ($total_files_home == 0) it returns 1 file even if directory is empty. What am I doing wrong? I am a novice in php.
Thank you for any help or a better solution.

Code: Select all

<?php
$total_files_home = 0; 
$total_files_home = count(glob("../users/$username/{*.*}", GLOB_BRACE));
if ($total_files_home <= 1)
$total_files_home = 0;
else
$total_files_home = $total_files_home;
 
echo '<a href="manager.php?efolder=home">';
echo '<img src="gfx/FolderIconV2.gif" border="0" alt="Home" width="60" height="50"><br>Home<br></a>( 
'.$total_files_home.' )<br><br></font>'; 
foreach(glob('../users/'.$username.'/*', GLOB_ONLYDIR) as $dir) {
$dir = str_replace('../users/'.$username.'/', '', $dir);
$total_files_sub = count(glob("../users/$username/$dir/{*.*}", GLOB_BRACE));
if ($total_files_sub <= 1)
$total_files_sub = 0;
else
$total_files_sub = $total_files_sub;
echo '<a href="manager.php?efolder='.$dir.'">';
echo '<font size=2>';
echo '<img src="gfx/FolderIconV2.gif" border="0" alt="'.$dir.'" width="60" height="50"><br>'.$dir.'<br></a>( 
'.$total_files_sub.' )<br><BR></font></a>';
}
 
?>