用php获取当前目录的路径?

I'd like to get the correct php code to display filepath to a folder on my server. Currently I put the actual filepath in my script which looks like this: /home/username/mydomain.com/dir/upload/

So the script is installed in a subfolder "dir", and I need the path to the "upload" folder

I used this, but it doesn't seem to work, because it seems to put uploaded files into the root:

$_SERVER["DOCUMENT_ROOT"] . '/upload' 

There is a __DIR__ constant which will contain the script file's directory path.

echo __DIR__;

So to get your upload path you could do:

echo __DIR__ . '/upload/';

For PHP < 5.3 you can do

echo dirname(__FILE__);

See http://www.php.net/manual/en/language.constants.predefined.php for other 'Magic Constants'