<?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.
Printable View
<?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.
<?php require("../include/const.php"); ?>
should do the trick
:)
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.
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:Quote:
Originally Posted by bigBA
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
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:
so, when he moves the file with you include, he also has to move the includes sub dir....Quote:
Because some PHP files may be moved.
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 :)
When faced with a similar issue, what I did was to use this:Quote:
Originally Posted by _mynameisno1
<?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