CodeVirtuoso
CodeVirtuoso

Reputation: 6448

PHP - The system cannot find the path specified. (but it finds it from another file)

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.

Upvotes: 1

Views: 8960

Answers (2)

hotS85
hotS85

Reputation: 1036

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).

Upvotes: 2

AshBrad
AshBrad

Reputation: 492

Depending on how you have your routing set up, does:

'./app/index.php/models/tricky.php'

produce a result?

Also, you might implement:

is_dir('app/models/');

and see what you get (it'll produce a boolean value.

Let me know the results and perhaps that'll lead us somewhere helpful.

Upvotes: 0

Related Questions