Good evening all,
I'm really struggling to find a way to list the directories of a given folder and also the subdirectories without adding in the files, as well as assigning them to a variable.
I've tried using getcwd, global, GLOB_ONLYDIR scandir, but can't get it to work out.
Is there anyway to assign each folder only to a variable?
$currentFolder2 = getcwd();
foreach (glob($currentFolder2 . '/*' , GLOB_ONLYDIR) as $dir) {
$files = glob($dir . '/*');
echo '<pre>'; print_r($files);
$link[0] = $files;
foreach (glob($files . '/*' , GLOB_ONLYDIR) as $dir) {
$subfiles = glob($dir . '/*');
echo '<pre>'; print_r($subfiles);
$sublink[0] = $files;
}
}
What I need to produce is folder links:
-Link to Folder1
-Link to Folder1-SubFolder1
-Link to Folder1-SubFolder2
-Link to Folder2
-Link to Folder2-SubFolder1
-Link to Folder2-SubFolder2
-Link to Folder2
-Link to Folder2-SubFolder1
-Link to Folder2-SubFolder2
It's not laying out the way I planned and it's also returning html pages for some reason.
Have I over complicated the way I am going about it or have I gone completely the wrong way.
Thanks in advance
$link[] = $files;
$files . '/*'
makes no sense.$files
is an array, not a string, you can't concatenate it.foreach ($files as $subdir) { $subfiles = glob("$subdir/*", GLOB_ONLYDIR); ... }