Jump to content

Recommended Posts

Good day to you all,

        here I have a recursive directory lister that puts everything into an array.

 

Here is the code:

 



<?
function getDirectory($path = '.', $ignore = '') {
    $dirTree = array ();
    $dirTreeTemp = array ();
    $ignore[] = '.';
    $ignore[] = '..';

    $dh = @opendir($path);

    while (false !== ($file = readdir($dh))) {

        if (!in_array($file, $ignore)) {
            if (!is_dir("$path/$file")) {
                
                $dirTree["$path"][] = $file;
                
            } else {
                
                $dirTreeTemp = getDirectory("$path/$file", $ignore);
                if (is_array($dirTreeTemp))$dirTree = array_merge($dirTree, $dirTreeTemp);
            }
        }
    }
    closedir($dh);
    
    return $dirTree;
}

$ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquota');

$dirTree = getDirectory('Photos', $ignore);
?>
<pre>
    <?
    print_r($dirTree);
    ?>
</pre>

 

 

My question is how can I keep the same array and without looping again through the directories again list only the folder ?

 

If i can, how can I also list a text only the folder that does have folder in them and as a link the one that as files.

 

So when a link is press I can list the array under that folder

 

Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/190398-list-as-array-and-modify-the-output/
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.