I try to run on all files in /images directory and I get disconnected when I reach the constructor part the directory is in the same directory as my php file:
$it = new FilesystemIterator('./images/');
foreach ($it as $fileinfo) {
echo $fileinfo->getFilename() . "\n";
}
The error I see is:
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'FilesystemIterator::__construct(/images/,/images/): The system cannot find the file specified. (code: 2)' in D:\wamp\www\MyHome2\php\images.php:9
you are (probably) using absolute paths when you want relative paths. use
$it = new FilesystemIterator('./images/');
or in your case, where you need to move "up" one folder, use ".." to move up:
$it = new FilesystemIterator('./../images/');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With