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

include()

P: n/a
I don't completely understand the documentation for the include() function:

"Files for including are first looked in include_path relative to the
current working directory and then in include_path relative to the directory
of current script. E.g. if your include_path is ., current working directory
is /www/, you included include/a.php and there is include "b.php" in that
file, b.php is first looked in /www/ and then in /www/include/. "

How do you know where "the current working directory" is?
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mike wrote:
How do you know where "the current working directory" is?


If you mean, how do you find out programmatically what it is, use the
getcwd() function.

If you mean, how do you as a programmer know what it should be ahead of
time, it's usually the directory containing the top-level script that's
being executed. (This may not hold true for command-line execution, but
should for web execution.)

So if the web server is loading up A.php, and A.php include()s B.php, in
B.php the working directory is still the location of A.php. (Unless of
course you've used chdir() to change it.)

-- brion vibber (brion @ pobox.com)
Jul 17 '05 #2

P: n/a

"Mike" <mi*******@nospam.msn.com> wrote in message
news:ad******************@bignews4.bellsouth.net.. .
I don't completely understand the documentation for the include() function:

"Files for including are first looked in include_path relative to the
current working directory and then in include_path relative to the
directory
of current script. E.g. if your include_path is ., current working
directory
is /www/, you included include/a.php and there is include "b.php" in that
file, b.php is first looked in /www/ and then in /www/include/. "

How do you know where "the current working directory" is?


It is identified in $_SERVER['SCRIPT_FILENAME']. It is the directory from
which the current top-level script is being run. This directory does not
change when you include() from another directory.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.