Skip to content
Advertisement

Get folder up one level

I am using this:

echo dirname(__FILE__);

which gives:

C:UwAmpwwwmyfolderadmin

However I am looking for path until:

C:UwAmpwwwmyfolder

from current script. How can that be done ?

Advertisement

Answer

You could do either:

dirname(__DIR__);

Or:

__DIR__ . '/..';

…but in a web server environment you will probably find that you are already working from current file’s working directory, so you can probably just use:

'../'

…to reference the directory above. You can replace __DIR__ with dirname(__FILE__) before PHP 5.3.0.

You should also be aware what __DIR__ and __FILE__ refers to:

The full path and filename of the file. If used inside an include, the name of the included file is returned.

So it may not always point to where you want it to.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement