Jump to content

Help getting correct file count "glob"


imagewiz

Recommended Posts

I am using the following code to return file count in directories, 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.

 

<?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>';

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/143319-help-getting-correct-file-count-glob/
Share on other sites

Try the following:

$username='';
$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>';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.