Aleks
Aleks

Reputation: 121

"require" doesn't include my file from the parent directory

I have a tree which looks like this :

enter image description here

I've been trying to includes file.php from AnotherFile.php :

enter image description here

I get this error :

enter image description here

Eventhough my IDE doesn't warn that the file is not found.

Upvotes: 0

Views: 1155

Answers (1)

aynber
aynber

Reputation: 23025

In instances like this, it's often better to use somewhat absolute paths instead of relative paths. You can make things easier with $_SERVER['DOCUMENT_ROOT'] to tell the code to start in your webroot instead of the system's root.

require_once($_SERVER['DOCUMENT_ROOT'].'/file.php');

Upvotes: 1

Related Questions