I am trying to find a way to always tell where the 'Base Directory' of a web direcory is relative to where I am browsing at the moment...
Example:
here is a sample web directory
/home/www/website/
the /website/ directory is the place where Apache is pointed to so .../website/ becomes http://foo.bar
(between front end and backend)
so I have a bunch of subdirectories underall that and sub-sub directories (....you get the point)
What is a good way to RELATIVLY point back to the base directory? (in thsi case that would be /home/www/website || http://foo.bar)
because typing:
include ("/home/www/website/inc/includeme.inc");
is not what I want to do, i'd much rather type:
if (!$BASEDIR) {
for($c=1; $c < substr_count($_SERVER["PHP_SELF"], "/"); $c++) {
$BASEDIR = $BASEDIR."../";
}
unset($c);
}
include ($BASEDIR."inc/includeme.inc");
This way I can migrate the entire site to another directory, or to another server, or whatever, and not have to recode, search-replace lines of code in larger sites.
The goal is portability. But is there a better way to do this than the $BASEDIR method I've been using above?
Thanks!