I am currently working on a my own project. A part of this is, give a file path and it searches that path/folder for all files and sub-folders and add those to an array.
This code send the file path "../" to the function wps_files and from this a whole multi-dimensional array is created.
The HTML.php
<?php
echo '<pre>';
print_r( wps_files('../') );
echo '</pre>';
?>
And here is the function inside the php script.
<?php
function wps_files($path) {
$wpsdir = Array(
'Root' => $path,
'Structure' => wps_glob($path)
);
return $wpsdir;
}
function wps_glob($dir) {
foreach (glob($dir . '/*') as $f) {
if(is_dir($f))
{
$r[] = array(basename($f) => wps_glob($f));
}
else
{
$r[] = basename($f);
}
}
return $r;
}
Now I want to create a fancy css file-tree. So here comes my question, how do i make from this array a proper written list? As in,
Every dimensional array is tagged inside a <ul></ul> and every item inside that array is also surrounded with <li></li> hard to explain, see this code. This is want i would like to achieve.
<ul>
<li>ROOT[the file where the search for folders/files starts in]
<ul>
<li>Index.php[file inside root]</li>
<li>Website[folder inside root]
<li>
<ul>
<li>HTML[folder inside Website]
<ul>
<li>Index.html</li>
<li>Contact.html</li>
<li>Info.html</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
I have been struggling to get this achieved but got nowhere so far. Help would be much appreciated, and explanation of course. Since i am here to learn. not to copy paste.
Thank you very much!
EDIT:
This is what currently is being displayed. It shows every file from the array, but not in the correct order.
0: Index.php
0: Javascript.js
1: Jquery.js
0: Get_Server_files.Script.php
0: General.css
1: Menu.css
2: Style.css
0: WelcomeImage0.png
1: WelcomeImage1.png
2: WelcomeImage2.png
3: WelcomeImage3.png
4: WelcomeImage4.png
5: WelcomeImage5.png
6: WelcomeImage6.png
WelcomeImages:
0
1: bg.jpg
HTML:
Javascript:
Scripts:
Style:
images:
0
1
2: New Text Document.txt
3
4
5