Hello Reader's! If you want to get all of the folder inside a given directory then PHP offers you many ways to do that, Lets see them from the basic programs.
you can use glob() with GLOB_ONLYDIR option
 here's how you can see how to retrieve only directories with GLOB:
$directories = glob($somePath . '/*' , GLOB_ONLYDIR);
Or if you want to make a recursive function then you can use the code as follows:-
<?php
    /*this will do what you asked for, it only returns the subdirectory names in a given
      path, and you can make hyperlinks and use them:
    */
    $yourStartingPath = "photos\\";
    $iterator = new RecursiveIteratorIterator( 
        new RecursiveDirectoryIterator($yourStartingPath),  
        RecursiveIteratorIterator::SELF_FIRST);
    foreach($iterator as $file) { 
        if($file->isDir()) { 
            $path = strtoupper($file->getRealpath()) ; 
            $path2 = PHP_EOL;
            $path3 = $path.$path2;
            $result = end(explode('/', $path3)); 
            echo "<br />". basename($result );
        } 
    } 
?>
Now the output of the code will be the folder names inside the directory.
                       
                    
0 Comment(s)