Reputation:
I am trying to use absolute paths to get a definitive reference to a config file.
For this, I am currently doing this:
require_once '../config.php'; //Works fine
But when I try this:
require_once '/config.php'; //Throws error, see below
The error I get is:
require_once(): Failed opening required '/config.php' (include_path='.;C:\php\pear')
Is this a thing in PHP 5.6.0 or am I missing something?
Upvotes: 0
Views: 147
Reputation: 33823
If you explicitly set the includes path in your script to the actual location it should be quite simple to include the files you need such as:
set_include_path( $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR );
require_once( 'config.php' );
Upvotes: 0
Reputation: 9001
Breaking down ../config.php
:
../
goes one directory above the working directoryconfig.php
finds the file config.php
in that directoryBreaking down /config.php
:
/
goes to the server rootconfig.php
finds the file config.php
in that directoryIf the first one works but not the second, it means that the file config.php
is not in the root folder, but is in the parent directory of the working file.
Upvotes: 2