By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,346 Members | 2,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,346 IT Pros & Developers. It's quick & easy.

Includes with muli-level directories

P: n/a
FP
I have the following files;
\A.php
\F1\B.php
\F1\F1_1\C.php

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;
\D.php
\F1\E.php
\F1\F1_1\F.php

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
doesn't exist.
If I change the include portion of file E to '../../D.php' then I get
"FED".

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
"SetupData.php" file.
How do I get the "ImageProxy.php" file to access the variables in the
"SetupData.php" file?
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?

Jun 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
FP wrote:
I also have files;
\D.php
\F1\E.php
\F1\F1_1\F.php

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
doesn't exist.


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.

Sincerely,
Alexander
http://www.alexatnet.com

Jun 16 '06 #2

P: n/a
FP
AlexVN wrote:
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.


You're right, just tried the "getcwd" command and the working directory
for all three files was always \F1\F1_1\

Thanks

Jun 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.