Re: Seeking help with relative and absolute paths [message #180818 is a reply to message #180817] |
Wed, 20 March 2013 05:45 ![Go to previous message Go to previous message](/forum/theme/default/images/up.png) ![Go to next message Go to previous message](/forum/theme/default/images/down.png) |
J.O. Aho
Messages: 194 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 20/03/13 05:45, The Frog wrote:
> I have a directory under the site root called config, and another called scripts. In the config directory I have some basic stuff like constants that I define for the site (eg/ db.php for the database constants such as username, server, etc...). Referencing this with the following php from index.php works fine:
> <?PHP require_once 'config/db.php';
> require_once 'config/config.php';
> //do stuff here
> ?>
>
> Where I am having a problem is when I try to reference the files from a script that is in the scripts directory (or any other for that matter). I have tried to set a constant in the config/config.php file that points to the root of the site with the following:
> define(APP_ROOT, realpath( dirname( __FILE__ ) ).'/');
You have the super global $_SERVER['DOCUMENT_ROOT'], so you can use
require_once $_SERVER['DOCUMENT_ROOT'].'/config/db.php';
ypu can also us the include_path in php.ini and add the path to the
document root in which case you then can use:
require_once 'config/db.php';
--
//Aho
|
|
|