Re: include files
| From: | Steve Werby | Date: | Mon, 05 Feb 2001 17:46:31 +0000 |
| Subject: | Re: include files | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-38276@lists.php.net to get a copy of this message | ||
"David VanHorn" <dvanhorn@cedar.net> wrote:
> I know this works, in footer.inc, to pull up nomenu.
> <? include("/home/dvh/public_html/footer-nomenu.inc")?>
>
> However, is there a more "generic" way to specify the server root as the
path?
> I'd rather not expose my directory structure in the PHP code.
How about the environment variable $DOCUMENT_ROOT (you may need to access as
$GLOBALS[DOCUMENT_ROOT] depending on your code). Put <?php phpinfo(); ?> in
a webpage to see all of the goodies available to you. I personally prefer
to keep the bulk of my PHP code outside the document root, in a directory
parallel to it. I define a constant INC_PATH typically parallel to the
document root using code similar to the following:
// Set INC_PATH.
ereg( "(.*)web_directory.*", $SCRIPT_FILENAME, $regs );
define( "INC_PATH", $regs[1] . "inc_directory/" );
Then I include files as follows:
include( INC_PATH . "inc_common.php" );
Very portable.
> I tried various versions of ../ and ../../ without success.
This isn't very portable anyway. You don't want to have to change paths if
you move a file to a deeper subdirectory.
--
Steve Werby
COO
24-7 Computer Services, LLC
Tel: 804.817.2470
http://www.247computing.com/