Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

explicit filepath to file in parent directory

Tags:

php

I have a situation where I have two config files.
A base config which resides in a parent directory, and a sibling config in a sibling directory.
To date, the sibling looks to the parent with a simple

require_once "../parent_config.php";

However I now want to pass the sibling into a new class system. I can pass an explicit filepath for the sibling no problem, but obviously run into issues with the above call to the parent.
I'm trying something along the line of the following but I'm getting it wrong somewhere (I'm trying to say take the explicit filepath, up one)

require_once (dirname(__FILE__) . "../parent_config.php");

I'd appreciate your comments.
Thanks
Giles

like image 249
giles Avatar asked Dec 02 '22 04:12

giles


1 Answers

Try

require_once realpath(dirname(__FILE__).'/..').'/parent_config.php';

Or for PHP 5.3+

require_once realpath(__DIR__.'/..').'/parent_config.php';

Or even just plain old this should work...

require_once __DIR__.'/../parent_config.php';
like image 113
Petah Avatar answered Dec 09 '22 10:12

Petah