PHP file outside doc root needs files outside and inside the document root
- by jax
I have a library of classes, all interrelated.
Some files are inside the document root and some are outside using the <Directory> and Alias features in httpd.conf
Assuming I have 3 files:
webroot.php (Inside the document root)
alias_directory.php (Inside a folder outside the doc root)
alias_directory2.php (Inside a **different** folder outside the doc root)
If alias_directory2.php needs both webroot.php and alias_directory.php, This does not work.
(Remember alias_directory.php and alias_directory2.php are not in the same locations)
require_once $_SERVER['DOCUMENT_ROOT'].'/webroot.php'; //(ok)
require_once $_SERVER['DOCUMENT_ROOT'].'/alias_directory.php'; //(not ok)
This does not work because alias_directory.php is not in the doc root.
Similarly
require_once $_SERVER['DOCUMENT_ROOT'].'/webroot.php'; //(ok)
require_once dirname(__FILE__).'/alias_directory.php'; //(not ok)
The problem here is that dirname(__FILE__) will return the path for alias_directory2.php not alias_directory.php.
This works:
require_once $_SERVER['DOCUMENT_ROOT'].'/webroot.php'; //(ok)
require_once '/full/path/to/directory/alias_directory.php'; //(ok)
But is very nasty and is a maintenance nightmare if I decide to move my library to another location.
How do I solve this problem, is seems that I need a way to resolve an Alias folder properly.