Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Includes with muli-level directories
June 16, 2006, 8:53 pm
rate this thread
File A has the lines "echo 'A'; include_once('F1/B.php');"
File B has the lines "echo 'B'; include_once('F2/C.php');"
File C has the line "echo 'C';"
If I open file A in my browser I get "ABC".
If I open file B in my browser I get "BC".
So far so good.
I also have files;
File D has the lines "echo 'D'"
File E has the lines "echo 'E'; include_once('../D.php');"
File F has the line "echo 'F'; include_once('../E.php');"
If I open file E in my browser I get "ED".
If I open file F in my browser I get "FE" and an error saying file D
If I change the include portion of file E to '../../D.php' then I get
Is this how PHP is suppose to work?
I have several files at the root level including a "SetupData.php" file
in which I need to specify IPs, passwords etc.
I have a directory "FX" and the file "ImageProxy.php" inside it.
The "ImageProxy.php" file is used as an include by files at the root
level but also called directly.
The "ImageProxy.php" file requires passwords stored in the
How do I get the "ImageProxy.php" file to access the variables in the
As far as I can tell it's possible to include a file by full path, if
possible I would like to avoid that, are there any other ways?
Re: Includes with muli-level directories
Please check the PHP manual on include function:
"If filename begins with ./ or ../, it is looked only in include_path
relative to the current working directory."
Please use the http://www.php.net/getcwd in your D,E,F scripts to check
what is current directory. I suspect that when the E.php is evaulated
in context of E.php, the working directory is still \F1\F1_1 so the
include_once('../D.php'); is trying to include \F1\F1_1\..\D.php, which
is does not exist.