Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FilesystemIterator is not working

Tags:

php

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

like image 832
Canttouchit Avatar asked Mar 06 '26 13:03

Canttouchit


1 Answers

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/');
like image 118
mnagel Avatar answered Mar 08 '26 02:03

mnagel



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!