Jump to content

Directory listing and array


synne

Recommended Posts

Sorry for such a simple question, or at least even I think it is.

What id like to do is create a function for creating a list of directories/folders in a given base directory and turn the results into an array. It does not have to be recursive. No files.

And prefer in alphabetical order

 

BaseUrl = '/';

BaseDir = '/path/to/dir';

 

For each directory create array as such:

 

$config['ResourceType'][] = Array(
                'name' => '$directory_name',
                'url' => $baseUrl . '$directory_name',
                'directory' => $baseDir . '$directory_name',
                'maxSize' => 0,
                'allowedExtensions' => 'htm,html,php,cgi',
                'deniedExtensions' => 'asp');

 

Thanks, and sorry again, Im reading on arrays and how to create the list, figuring out how to put them together is driving me nuts

Link to comment
https://forums.phpfreaks.com/topic/260355-directory-listing-and-array/
Share on other sites

You could use the glob() function (docs) to get a list of directories.  The idea being to build up your array in a loop like:

 

 

$directories = glob($baseDir . '/*', GLOB_ONLYDIR);
foreach ($directories as $directory_path) {
    $directory_name = basename($directory_path);
    $config['ResourceType'][] = array(
        'name' => $directory_name,
        'url'  => $baseUrl . $directory_name,
        // and the rest of your array values
    );
}

 

 

 

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.