Re: Setting or Getting Relative Path for PHP Includes

From: Date: Tue, 21 Dec 2004 03:52:25 +0000
Subject: Re: Setting or Getting Relative Path for PHP Includes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-204927@lists.php.net to get a copy of this message
* Thus wrote Anthony Baker: > Hey Folks, > > Hoping someone can aid me with a newbie-ish question. > > I often use PHP includes in my files to pull in assets, but I hard code > the relative path to the root html directory for the sites that I'm > working on in each file. Example below: > > <?php > $path = '/home/virtual/sitename.com/var/www/html/'; > //relative path to the root directory > $inc_path = $path . 'code/inc/'; > //path and folder the code includes folder is located > $copy_path = $path . 'copy/'; > //path and folder the copy is located > ?> > > > I'd like to be able to set the relative path as a global variable from > an external file so that I can modify one line of code to change the > relative path across the site. This will allow me for easier coding in > staging and development environments. This is a good use of the define() function, what I would generally do is create a config.php of some sort with: <?php define('_BASE_INCLUDE_', '/home/path/'); define('_INCLUDE_INC_', _BASE_INCLUDE_ . 'code/inc/'); define('_INCLUDE_CPY_', _BASE_INCLUDE_ . 'code/copy/'); ?> And each file that needs this config: <?php require_once('config.php'); // having config.php in your // php_include_path ?> Curt -- Quoth the Raven, "Nevermore."

« previous php.general (#204927) next »