Reputation: 1699
I'm having the following error when trying to require_one a file:
Uncaught require_once(../web/common/config.php): failed to open stream: No such file or directory
I'm calling trying to make this require from a file that is inside a folder called 'tests' that's at the same level of the folder 'web'. From what I see, by using ../ I'm going to the same level of both folders, and then by calling /web... I was able to get to the file I need.
My folder structure is the following:
The require is called from dbTest.php
What's missing?
Upvotes: 0
Views: 238
Reputation: 116190
The path used is the path of the main file, not the path your include file 'dbTest.php.
To prevent issues like that, make it an absolute path using the __DIR__
constant:
require_once(__DIR__ . '/../web/common/config.php');
That ('magic') constant always contains the path of the file that uses it.
Upvotes: 1