Jump to content

PHP - Display ALL files in ALL folders in a specific directory.


Gamerz

Recommended Posts

Hello,

 

So I would like to display everything INSIDE a specific directory. In other words, I would like to display all file name's inside all subfolders in a specific directory. (NOT the subfolder itself...but whats inside. See example.)

 

Example:

The ROOT directory is: /root/

The directory that ALL folder's will be located is: /root/folder_names/

I have several subfolders: /root/folder_names/folder 1, /root/folder_names/folder 2, /root/folder_names/folder 3, and so on.

 

I would like it to display all FILE NAMES in folder 1, folder 2, folder 3; but not the folders. How would I do this? Thanks so much for the help.

Use the glob function. Here is an example, I've not tested it though.

foreach (glob("/folder_names/", GLOB_ONLYDIR) as $dir) {
    $folder = explode("/", $dir);
    $folder = $folder[count($folder)-1];
    //echo $folder . "<br />";

    foreach (glob($dir . "/*", $file)) {
        $file = basename($file);
        echo "<a href='$file'>$file</a><br />";
    }
}

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.