RecursiveDirectoryTerator在上给出意外值执行
$path= WEB."sync_content/offer/";
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
$fn=$file->getFilename();
if($fn!='.' && $fn!='..' && !is_dir($fn)) {
$filePath = $file->getRealPath();
$zip->addFile($filePath,$fn);
}
}
错误是:
致命错误未捕获异常"UnexpectedValueException",消息为"RecursiveDirectoryTerator::__construct"(http://localhost/base/sync_content/offer/):无法打开目录:未在C:''examplep''htdocs''base''classes''campaigns.class.php 249 中实现
您似乎正在使用URL("http://localhost/..."),这对RecursiveIteratorIterator不起作用。您最好将$path
设置为直接指向本地目录,如$path = "/full/path/to/base/sync_content/offer/"
。
您可以使用try
catch
来处理特定的错误消息,在我的情况下是permission issues
对于网页,不能使用RecursiveIteratorIterator。这只能应用于本地目录。URL不是目录,这就是它失败的原因。