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.

Link to comment
Share on other sites

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 />";
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.