【发布时间】:2023-04-07 11:59:01
【问题描述】:
我正在完成一个列出目录中文件的代码段。我在目录中列出文件没有问题,但由于某种原因,我可以让 isDot() 方法工作以确保文件不是“。”要么 ”..” 。以下导致此错误:
Fatal error: Call to undefined method SplFileInfo::isDot() in ....
在我切换到使用递归迭代器之前,我使用的是目录迭代器,它运行良好。下面的代码有什么问题吗?它应该可以工作。
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pathToFolder));
//if there is a subdirectory it makes sure the proper extension is passed
foreach($files as $name => $file){
if (!$file->isDot()) { //this is where it shuts me down
$realfile = str_replace($pathToFolder, "", $file);
$url = getDownloadLink($folderID, $realfile);
$fileArray[] = $url;
}
}
【问题讨论】: