问题
RecursiveDirectoryIterator gives Unexpected Value Exeception
$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);
}
}
And the error is:
fatal error Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(http://localhost/base/sync_content/offer/): failed to open dir: not implemented in C:\xampp\htdocs\base\classes\campaigns.class.php 249
回答1:
You seem to be accessing the local storage using a URL ("http://localhost/..."), which won't work for RecursiveIteratorIterator. You may be better off setting $path
to point directly to the local directory instead, like $path = "/full/path/to/base/sync_content/offer/"
.
回答2:
You can use try
catch
for specific error msg in my case its permission issues
回答3:
You cannot go with RecursiveIteratorIterator for web pages. This can be applied to local directories only. The URL is not directory, that's why it's failing.
来源:https://stackoverflow.com/questions/29491037/recursivedirectoryiterator-gives-exception