This is normally done in PHP using the __DIR__
magic constant, like this:
require_once(__DIR__ . '/path/to/file.php');
To get to your top-level from a different embedded directory, you can do something like this::
require_once(__DIR__ . '/../dir_libs/top.php');
For versions of PHP previous to 5.3.0, you can use dirname(__FILE__)
in place of __DIR__
.
For a real-world example, you can look at the Laravel project, which uses a few different tricks in the .php
files found in the public
and bootstrap
directories to reference other files in the project:
https://github.com/laravel/laravel/tree/v4.1.18
(I've linked to the current version, in case it changes later on.)