-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonTree.php
executable file
·54 lines (43 loc) · 980 Bytes
/
jsonTree.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
$a= array();
function listAllDir($path,$i,$parent,$a)
{
global $a;
$d = @opendir($path);
//echo $d;
//echo "<ul><li>";
//$array()=0;
$dirname = end(explode("/",$path));
$a['tree'.$i]['id'] = "$i";
$a['tree'.$i]['parent'] = "$parent";
$a['tree'.$i]['text'] = "$dirname";
//echo "$dirname<ul>";
while(false !== ($f=readdir($d)))
{
if($f== "." || $f=="..")
continue;
else
{
//echo "<li><p> $f</p></li>";
if(is_dir($path."/".$f))
{
// echo "<li id='child_node_1'>";
listAllDir($path."/".$f,$i+1,$parent,$a);
}
else
{
$a['tree'.$i]['id'] = "$i";
$a['tree'.$i]['parent'] = "$i";
$a['tree'.$i]['text'] = "$f";
}
}
}
closedir($d);
//echo "</ul></li></ul>";
}
//$a[3] = "HI";
listAllDir(".",1,0,$a);
//$b=array();
//xyz();
echo json_encode($a);
?>