Jump to content

Why is DOCUMENT_ROOT different than what I get with getcwd() ?


guttyguppy

Recommended Posts

Here's my code:

 

$curDir=getcwd();
$docRoot=$_SERVER['DOCUMENT_ROOT'];
echo "current dir is:".$curDir;
echo "<br/>";
echo "doc root is:".$docRoot;

 

 

I'm getting :

current dir is:/home/username/public_html

doc root is:/var/www/

 

Why aren't those the same thing? I am having a really hard time understanding server environments, directory paths, so if you can forward any enlightening tutorials/explainations, it would be greatly appreciated. I've checked php.net, but I still don't get it.

Thanks!

cwd is the current working directory and DOCUMENT_ROOT is:

The document root directory under which the current script is executing, as defined in the server's configuration file.
See: http://www.php.net/manual/en/reserved.variables.server.php

 

The current working directory changes depending on what's going on. If you are calling: www.yoursite.com/index.php the cwd would be something like what you said "/home/username/public_html" if you executed the same script in a sub-directory: www.yoursite.com/subDirectory/index.php the cwd would now be "/home/username/public_html/subDirectory" but DOCUMENT_ROOT would not change because it is what it says above.

 

You can change the current working directory in your scripts too, using functions like chdir() http://au2.php.net/manual/en/function.chdir.php

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.