Asked  2 Years ago    Answers:  5   Viewed   85 times

I have this working function that finds folders and creates an array.

function dua_get_files($path)
    foreach (glob($path . "/*", GLOB_ONLYDIR) as $filename)
        $dir_paths[] = $filename;   
    return $dir_paths;

This function can only find the directories on the current location. I want to find the directory paths in the child folders and their children and so on.

The array should still be a flat list of directory paths.

An example of how the output array should look like

$dir_path[0] = 'path/folder1';
$dir_path[1] = 'path/folder1/child_folder1';
$dir_path[2] = 'path/folder1/child_folder2';
$dir_path[3] = 'path/folder2';
$dir_path[4] = 'path/folder2/child_folder1';
$dir_path[5] = 'path/folder2/child_folder2';
$dir_path[6] = 'path/folder2/child_folder3';



If you want to recursively work on directories, you should take a look at the RecursiveDirectoryIterator.

$path = realpath('/etc');

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
    echo "$namen";
Thursday, October 13, 2022

This note on the manual page of glob() seems to answer your question, saying that glob is not limited to a single directory : using GLOB_BRACE, you can specify several directories.

I'm quoting the example that @Ultimater gives there :


User-notes on the manual pages often contain useful informations and examples ;-)

Sunday, September 11, 2022

Check out the resource at and make sure you have everything configured as-described.


  1. Ensure that your debugger is set up correctly in php.ini
  2. Uncomment the string in php.ini
  3. Restart your web-server (if you are on modphp)
  4. Make sure that in your phpinfo() you have set xdebug
Thursday, August 4, 2022

The problem looks you have put your php file in gallery folder...

/home/a9773555/public_html/gallery/index.php on line 2

if that is the case (if you put index.php in gallery) then try the following:

    foreach(glob('images/*', GLOB_NOSORT) as $image)   
        echo "Filename: " . $image . "<br />";      

Or do the following,

Put your index.php in your /home folder. then...

    foreach(glob('a9773555/public_html/gallery/images/*', GLOB_NOSORT) as $image)   
        echo "Filename: " . $image . "<br />";      

Give it a try. and let me know...

Monday, August 29, 2022

I would suggest you look at the MVC Design Pattern so that you understand it before you start using it.

Ideally, you should already have made some projects where you suffered a little bit because you wanted to change stuff when your project was at least halfway done.(This is one of the main motivators behind a lot of so-called advanced programming techniques. Ease of modification, flexibility and so on).

This is where stuff like what you mentioned (OO,MVC, and I would add TDD, Design Patterns) all come in).

What I do for myself and suggest others do is the following. Look into whatever you want, be it TDD, MVC or any other advanced technique. But wait until you need them.

In my personal opinion, one can much better appreciate the value of OO and MVC when one has gone through a naïve project and suffered from lack of functionality these techniques provide...

The golden rule is.. only start using a new technique when you've understood it and seen what benefits it can bring.

I say that because what I see in real life is that many people use stuff like OO, MVC and even Design Patterns without understanding the why's behind. I don't think that helps at all.

Good luck.

Saturday, August 6, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :

Browse Other Code Languages