Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecursiveDirectoryIterator gives exception

Tags:

php

scandir

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

like image 723
dEL Avatar asked May 01 '26 01:05

dEL


2 Answers

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

like image 94
mhall Avatar answered May 02 '26 16:05

mhall


You can use try catch for specific error msg in my case its permission issues

like image 41
Saurabh Chandra Patel Avatar answered May 02 '26 16:05

Saurabh Chandra Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!