I have a method which looks through a directory and returns an array of the file structure, an example of this is as follows;
Array
(
[0] => filename.png
[directory] => Array
(
[subdirectory] => Array
(
[0] => filename.jpg
)
)
[directory] => Array
(
[0] => filename.png
)
[directory] => Array
(
)
[directory] => Array
(
[0] => filename.png
)
[directory] => Array
(
[0] => filename.png
)
)
The code that I used to build that up is as follows;
function dirToArray($dir) {
$contents = array();
foreach (scandir($dir) as $node) {
if ($node == '.' || $node == '..') continue;
if (is_dir($dir . '/' . $node)) {
$contents[$node] = dirToArray($dir . '/' . $node);
} else {
$contents[] = $node;
}
}
return $contents;
}
I need flatten this down so i can display it, exactly like what you see here;
filename.png
directory
.. subdirectory
.. .. filename.png
directory
.. filename.png
directory
.. filename.png
directory
.. filename.png
The problem is, i need to input the data in a json structure that doesnt change. The description of the structure is as follows: Full path to the file then text to display and lastly 'leaf' ( file = true, directory = false )
This is how it should look;
[ ['fullpath', 'displaytext', 'true'],['fullpath', 'displaytext', 'false'] ]
I'm really confused on how to go about this, any help would be greatly appreciated.
Thank you