is this pointing to the directory where the current file is executed?
-
2'document_root' is NOT the same as "DOCUMENT_ROOT". – ghostdog74 Jan 15 '10 at 14:25
7 Answers
No, it points to the root of your webserver - the topmost folder of your website.
If you want the directory of the current file, use:
dirname(__FILE__);

- 28,281
- 7
- 65
- 99
-
+1: This is the correct way to do it. (I realize I posted this twice, but the two answers mentioning this solution were literally posted 1 second apart... 49 and 50 seconds before I loaded this page) – Powerlord Jan 15 '10 at 14:26
From http://php.net/manual/en/reserved.variables.server.php
'DOCUMENT_ROOT' The document root directory under which the current script is executing, as defined in the server's configuration file.

- 51,659
- 8
- 55
- 58
Maybe, depending on how the server is set up. A much better method is:
echo dirname(__FILE__); // return the absolute file-path to where the current PHP file is

- 19,057
- 21
- 82
- 129
No, it's not,
DOCUMENT_ROOT
points to the root directory of your webserver, while PATH_INFO
points to the directory where the current file is executed.

- 22,092
- 4
- 54
- 76
-
Sorry, but you're wrong. If I have a address http://myhost/my/path/xyz.php/foo/bar, then PATH_INFO contains foo/bar. – Rolf Sep 06 '14 at 20:31
-
Oops, took too much time editing :) DOCUMENT_ROOT is a pysical server path, but PATH_INFO is a pseudo-path that is appended to the name of the php script, like this: http://myhost/my/path/xyz.php/foo/bar. foo/bar will usually be an internal route in your logic. Your PHP is free to interpret it as a server path, but that's not mandatory. The browser, on the other hand, knows nothing about that and thinks that my/path/xyz.php/foo/bar is the "current object", and when you refer to a CSS oder image by "./sna.foo" then you'll be surprised. – Rolf Sep 06 '14 at 20:44
'DOCUMENT_ROOT'
The document root directory under which the current script is executing, as defined in the server's configuration file.

- 13,652
- 14
- 67
- 96
The document root directory under which the current script is executing, as defined in the server's configuration file.
as the name implies it's a root directory.

- 307,395
- 66
- 306
- 293
Yes it is. It's a path relative to the root of your server (not your document root) that describes the directory of the current script. It does not have a trailing slash.

- 13,492
- 9
- 47
- 68