2
我想从特定路径文件夹ID和子文件夹parent_id中获取文件夹和子文件夹。 在这里我的功能获取文件夹和子文件夹,但没有ID和父母的ID。如何检索包含文件夹ID的数组中的目录结构
我想用id和父id的数组。
function getDirectory($path = '.', $level = 1) {
$result = array();
$ignore = array('nbproject', 'src', '.', '..');
$dh = @opendir($path);
$i = 0;
while ($file = readdir($dh)) {
if (!in_array($file, $ignore)) {
if (is_dir($path . '/' . $file)) {
$level++;
$singleResult = array('title' => $file, 'isFolder' => true, 'children' => getDirectory($path . '/' . $file, $level), 'key' => 'node' . $level);
$result[] = $singleResult;
}
}
$i++;
}
closedir($dh);
return $result;
}
$dir = "../UserUpload/Documents/source";
$kevin = getDirectory($dir);
这个功能给我数组这样wiithout ID和父ID
array (size=3)
0 =>
array (size=4)
'title' => string 'mst146' (length=6)
'isFolder' => boolean true
'children' =>
array (size=3)
0 =>
array (size=4)
...
1 =>
array (size=4)
...
2 =>
array (size=4)
...
'key' => string 'node2' (length=5)
1 =>
array (size=4)
'title' => string 't124' (length=4)
'isFolder' => boolean true
'children' =>
array (size=0)
empty
'key' => string 'node3' (length=5)
2 =>
array (size=4)
'title' => string 'test' (length=4)
'isFolder' => boolean true
'children' =>
array (size=0)
empty
'key' => string 'node4' (length=5)
你是什么意思的ID?文件夹通常没有ID。 – maxhb
但我想给id文件夹@maxhb –
ID应该从哪里来?如果您只需要与文件夹相关的独特内容,请使用它的路径。 – maxhb