此代码输出一个数组,其中包含dir文件夹中的目录
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
$data = scandir('../dir/');
echo json_encode($data);
服务器上的文件夹树是这样的
dir/one/oneChild
dir/two/twoChild
dir/three/threeChild
我想得到这样的JSON格式的东西,即dir文件夹中的整个文件夹结构
[
{
"one": {
"oneChild": {}
}
},
{
"two": {
"twoChild": {}
}
},
{
"three": {
"threeChild": {}
}
}
]
例如,您可以通过这种方式递归。