problem:
A very simple directory listing isnt pulling all the files and I'm pulling my hairs trying to figure out why:

function DirReader($dir){
if ($handle=opendir($dir)){
while($file = readdir($handle)){
if (is_file($file)) echo "<b>".$dir."/</b>".$file." is a file<br><br>"; 
elseif ((is_dir($file)) && (trim(str_replace(".", "",$file)) !== "")) {
DirReader($dir."/".$file); 
}
}
}
}

DirReader("."); 

As you can see, not much to the code, but it seems to only pull 1 or 2 files, perhaps until it finds a directory, on any given directory.

typical readout:
./file.php is a file
./index.php is a file
./ext/index.php is a file
./file2.php is a file
when the ext/ has alot more files then listed

    You need to change this line

    is_dir($dir."/".$file))

      Thanks HalfaBee, but that didnt do the trick yet.

        Missed the other one.

        <?php
        
        function DirReader($dir){
            if ($handle=opendir($dir)){
                while($file = readdir($handle)){
                    if (is_file($dir.'/'.$file))
                        echo "<b>".$dir."/</b>".$file." is a file<br><br>";
                    elseif ( (is_dir($dir.'/'.$file)) && (trim(str_replace(".", "",$file)) !== "") ) {
                        DirReader($dir."/".$file);
                    }
                }
            }
        }
        
        DirReader(".");
        
        ?>

          I assume you're wanting to list all files by drilling down from directory $dir...

          If so, this should work for you...

          <?php
          function DirReader($dir)
          {
          if ($handle=opendir($dir))
          {
          while($file = readdir($handle))
          {
          $file_path = $dir.'/'.$file;
          if(is_file($file_path))
          {
          echo "<b>".$dir."/</b>".$file." is a file<br><br>";
          }
          elseif ((is_dir($file)) && (trim($file != '.')) && (trim($file != '..')))
          {
          DirReader('./'.$file);
          }
          }
          }
          }
          DirReader(".");

          ?>

            Dare i suggest glob() as being much easier to work with for this.

              Write a Reply...