PapT PapT - 1 year ago 123
PHP Question

Get path to current directoty with 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/

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'

Answer Source

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 for other 'Magic Constants'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download