synne Posted April 4, 2012 Share Posted April 4, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260355-directory-listing-and-array/ Share on other sites More sharing options...
salathe Posted April 4, 2012 Share Posted April 4, 2012 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 ); } Quote Link to comment https://forums.phpfreaks.com/topic/260355-directory-listing-and-array/#findComment-1334445 Share on other sites More sharing options...
synne Posted April 4, 2012 Author Share Posted April 4, 2012 That was perfect, hope it was as easy as it looks. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260355-directory-listing-and-array/#findComment-1334452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.