2

is this pointing to the directory where the current file is executed?

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
ajsie
  • 77,632
  • 106
  • 276
  • 381

7 Answers7

8

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__);

Adam Hopkinson
  • 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
1

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.

rogeriopvl
  • 51,659
  • 8
  • 55
  • 58
1

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
Extrakun
  • 19,057
  • 21
  • 82
  • 129
1

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.

Harmen
  • 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
0

'DOCUMENT_ROOT'
The document root directory under which the current script is executing, as defined in the server's configuration file.

http://www.php.net/manual/en/reserved.variables.server.php

Ben Everard
  • 13,652
  • 14
  • 67
  • 96
0

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.

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
0

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.

mattbasta
  • 13,492
  • 9
  • 47
  • 68