Re: Virtual includes
| From: | David T-G | Date: | Mon, 26 Aug 2002 09:44:32 +0000 |
| Subject: | Re: Virtual includes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-114117@lists.php.net to get a copy of this message | ||
Gregory --
[You know, you shouldn't just reply to any old message and start a new
topic; send a fresh message to the list instead so that it will be the
start of a new thread.]
..and then Gregory Barker said...
%
% Hi all,
Hello!
%
% I'm trying include .php files which reside in alternative directories or
% sub-directories. Such as a file which reside in www/chat/page.php, and for
% this page I would like to include a file which resides in www/forum/include/
That can definitely be done.
%
% I've tried the following which just results in a error:
% include '/forum/include/test.php'; aqnd multiple variations of it.
Ah, but you're using the website-based path instead of the actual path in
the filesystem. You're not including a URL, but a file, so you should
spell it out.
%
% How do I get around this problem?
The simplest way to start is to just give the full path:
include /path/to/site/www/forum/include/test.php ;
although that begins to be cumbersome once you start including lots of
stuff from here and there. You might simplify it a bit and just
include $_SERVER[DOCUMENT_ROOT]/forum/include/test.php ;
to make your code reusable in any web site dir, since the variable will
expand to whatever the doc root is (like /path/to/site/www). You might
want to be even more general, though, and pull something from the parent
directory; you might use
$currdir = getcwd() ;
include $currdir . "/../parentdirfile.php" ;
to do that.
As always, RTFM. See "Directory functions" and "Filesystem functions"
for starters on this type of task.
%
% Greg
HTH & HAND
:-D
--
David T-G * It's easier to fight for one's principles
(play) davidtg@justpickone.org * than to live up to them. -- fortune cookie
(work) davidtgwork@justpickone.org
http://www.justpickone.org/davidtg/ Shpx gur
Pbzzhavpngvbaf Qrprapl Npg!