Это хороший прием, что бы включать файл на оюбом уровне сата или есть по-лечше? С $DOCUMENT_ROOT иногда проблема, пхп теряет путь, а иногда нет. Мне надо, что бы это на всех серваках при любой конфигурации работало.
Код:
<? $success = @include_once(dirname(__FILE__)."/elem/config.inc.php");
if (!$success) { echo "Include failed"; } ?>
Код:
А это?
<?php
function getPath() {
// get position of current file
$path = $GLOBALS["PATH_INFO"];
// save a few nanaseconds, has this been done before,
// has the global variable been set ?
if (!isset($definedPath)) {
// is file in root already ?
if (strrpos($path,"/")!=0) {
// there is probably a quicker way to count
// the "/"s in the path
$path=explode("/",$path);
$s="";
for ($i=0;$i<count($path)-1;$i++) {
if ($path[$i]!="") {
// add the number of "../"s required
$s.="../";
}
}
// declare a global variable so you dont have to
// do this again, and return the variable
global $definedPath;
$definedPath=$s;
return $definedPath;
}
} else {
// just return what it worked out before, function
// only really runs once
return $definedPath;
}
}
include getPath() . "my_include_path/header.inc";
include getPath() . "includes/somethingelse.inc";
//above file is at mydomain.com/includes/somethingelse.inc
include getPath() . "includes/footer.inc";
?>