RecursiveDirectoryIterator gives exception

假装没事ソ 提交于 2019-12-13 02:19:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!