RecursiveDirectoryIterator gives exception

dEL picture dEL · Apr 7, 2015 · Viewed 9k times · Source

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

Answer

mhall picture mhall · Apr 7, 2015

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/".