John Dong
John Dong

Reputation: 65

"../" (back directory) not working on PHP in Windows

I have no clue why it's not working but when I go to debug my code it doesn't work and just throws an error like this:

Fatal error: require(): Failed opening required '../classes/John/settings.php' (include_path='.;C:\xampp\php\PEAR')

Directory Structure: http://gyazo.com/220cf2d603f8f1267260b2dd72d2d46d

Upvotes: 0

Views: 57

Answers (1)

leshy84
leshy84

Reputation: 700

You shouldn't be performing includes relative to the current directory. What if you wanted to move that file? All of the links would break. A way to ensure that you can still link to other files, while retaining those links if you move your file, is: require_once($_SERVER['DOCUMENT_ROOT'] . 'directory/directory/file');

DOCUMENT_ROOT is a server variable that represents the base directory that your code is located within.

Upvotes: 1

Related Questions