【发布时间】:2017-12-15 10:06:36
【问题描述】:
大家好,我有一个递归函数可以获取 ftp 目录和文件,但我无法获取某些文件夹的内容,例如测试文件夹 /public_html/test/myfiles.html 我没有得到 test 中的内容,否则该功能可以正常工作。
这是我的代码:
function ftpRecursiveFileListing($ftpConnection, $path, $parentId = null) {
static $cnt = 0;
$files = array();
$contents = ftp_nlist($ftpConnection, $path);
foreach($contents as $currentFile) {
$currentFileArray = array();
$filesize = ftp_size($ftpConnection, $currentFile);
$currentFileArray["text"] = $currentFile;
$currentFileArray["parent_id"] = $parentId;
$currentFileArray["id"] = $cnt++;
$currentFileArray["filesize"] = NULL;
if($filesize >= 0)
$currentFileArray["filesize"] = $filesize; // octets
// assuming its a folder if there's no dot in the name
if (strpos($currentFile, '.') === false)
$currentFileArray["children"] = $this->ftpRecursiveFileListing($ftpConnection, $currentFile, $currentFileArray["id"]);
$files [] = $currentFileArray;
}
return array_reverse($files) ;
}
【问题讨论】:
-
也许,只是一些子文件夹不是全部
-
所以你对递归函数没有问题,对吧?您在列出几个特定目录时遇到问题。所以向我们展示一个简单的代码,它明确列出了一个有问题的目录。
-
例如:我有一个文件夹“父”包含另一个文件夹“子”。当我从 / 根移动文件名“index.html”时。到 /parent/child/index.html 它工作正常我得到了结果但是当我将最后一个 /child/**index.html** 从 index.html 重命名为 default.html 或 yourname.html 我没有得到任何结果,这太疯狂了