how to specify the root directory of the web site?
<?php require("include/const.php"); ?>
In the quotation marks.
"/" can't be used.
I want to include the file in "http://mywebsite/include/", but I don't want to specify the website name.
# 1 Re: how to specify the root directory of the web site?
<?php require("../include/const.php"); ?>
should do the trick
# 2 Re: how to specify the root directory of the web site?
:)
I know how to use "../",
but can I specify the root directory simply?
Because some PHP files may be moved.
If so, I'd have to modify each file.
# 3 Re: how to specify the root directory of the web site?
you have to specify the path on your server to the include file with phps include directive.
so if your include file lies at /usr/local/apache/htdocs/include/functions.inc
then you can do a include( '/usr/local/apache/htdocs/include/functions.inc' );
bigBA at 2007-11-10 4:00:15 >

# 4 Re: how to specify the root directory of the web site?
you have to specify the path on your server to the include file with phps include directive.
so if your include file lies at /usr/local/apache/htdocs/include/functions.inc
then you can do a include( '/usr/local/apache/htdocs/include/functions.inc' );
using a full path like that isn't ver "portable", it won't work well on some other systems, try something like this:
include(dirname(__FILE__)."/includes/const.php");
That would make it so that wherever your file is, it will always look for the /includes/const.php file
hope it helps,
camowel
# 5 Re: how to specify the root directory of the web site?
well (IMHO), this should have the same effect like include('includes/const.php'), means that includes is a subdirectory of the directory where the files is in which this include statement lies.
but the op says:
Because some PHP files may be moved.
so, when he moves the file with you include, he also has to move the includes sub dir...
but you are right, this isn't very portable :) - but if you have to move you php files from one machine to another... which aren't equally configured, you have a lot of work to do, maybe modifying each page, too... so changing those includes wouldn't count :)
bigBA at 2007-11-10 4:02:27 >

# 6 Re: how to specify the root directory of the web site?
<?php require("include/const.php"); ?>
In the quotation marks.
"/" can't be used.
I want to include the file in "http://mywebsite/include/", but I don't want to specify the website name.
When faced with a similar issue, what I did was to use this:
<?php include "start.php" ?>
and then I put a little file (mine are only 1 line each) called start.php in each directory with info specific to that directory, as in WHAT directory it is. :)
Once you have that, you can define (in start.php) a constant to hold the current directory and the base directory and then use that to include your files.
Were you to port the system, only the start.php files would need editing.
Hershel