Reputation: 5568
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
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
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