sehummel
sehummel

Reputation: 5568

Getting the path of a file in PHP three levels up from the current directory

I'm trying to access a folder three levels up from my working directory with file_put_contents(). Here is my working directory.

Users/myMac/Sites/mini-configurator/miniconfig/application/controllers 

I need to get to the 'mini-configurator' folder and then into a subfolder of that called 'mc'. I can get the path of the file in PHP with dirname(__FILE__). How do I use that to get to the mini-configurator folder.

I tried dirname('../../../ . __FILE__), but it didn't work.

Upvotes: 0

Views: 1988

Answers (3)

Belac
Belac

Reputation: 1083

Having dealt with this recently, I've found something like:

$path = dirname(dirname(dirname(__DIR__)));

a little easier to read. YMMV.

Upvotes: 1

shootingrubber
shootingrubber

Reputation: 145

Just use an absolute directory structure:

$path = $_SERVER["DOCUMENT_ROOT"] . "/../.../...."; 
//in the quotes just set it to the path from the root directory

Upvotes: 0

Ibu
Ibu

Reputation: 43850

did you try

$path = dirname(__FILE__)."/../../../";

Upvotes: 2

Related Questions