There are two problems in your code.
The first is the directory separator - you should use the constant DIRECTORY_SEPARATOR
instead of \
, e.g.:
$directory = explode(DIRECTORY_SEPARATOR, $path);
This will make your code valid not only on windows but also on unix systems.
The second problem is here:
$htmlTree = createTree($directory[$pathx]);
There is no key $pathx
in the $directory
array. Probably it should look like this:
$htmlTree = createTree($directory);
But please note that it's hard to tell what results you expect and what errors did you get.