My main app is at:
'.app/index.php'
What I do from there is parse a directory
foreach (new DirectoryIterator('./app/uploads/images/') as $fileInfo) {
if($fileInfo->isDot()) continue;
$images[] = $fileInfo->getFilename();
}
And it works ok.
But, when I do the exact same thing from
'./app/models/tricky.php'
I get the error from the title.
Any clue what I’m doing wrong?
I also tried modifying path to '../app/uploads/images/'
but have no clue what else to do.
Thanks.
The difference and simple problem is:
You’re two scripts are not in the same directory. If you use the ‘./directory’ notation, the ‘.’ means starting at your current directory which is one time ‘app’ and the other time ‘app/models/’.
Solve the problem by changing the path string in ‘app/models/tricky.php’ to ‘../uploads/images/’. The double dot ‘..’ is important, it stands for the parent directory (go one directory up).