I am stuck with the following problem. I have the following recursive reading directory php function.
<?php
//a simple file tree traversal - takes in a path and returns a nested array
$delim = strstr(PHP_OS, "WIN") ? "\\" : "/";
function retrieveTree($path) {
global $delim;
if ($dir=@opendir($path)) {
while (($element=readdir($dir))!== false) {
if (is_dir($path.$delim.$element) && $element!= "." && $element!= "..") {
$array[$element] = retrieveTree($path.$delim.$element);
} elseif ($element!= "." && $element!= "..") {
$array[] = $element;
}
}
closedir($dir);
}
return (isset($array) ? $array : false);
}
?>
This function is taken from http://devzone.zend.com/283/recursion-in-php-tapping-unharnessed-power/ It reads an directory and it's subdirectories, for example:
foo/baz
foo/baz/bop
foo/baz/bop/file4.txt
foo/baz/file2.txt
etc/
And it will create an array with directory and files format.
It works well but I like to create a directory tree. How could I change this function to create a list like structure as follows.
<ul>
<li>foo
<ul>
<li>baz
...
</ul>
</li>
...
<li>etc
...
</ul>
I tried alot of things with no success.