//首先确保 $_SERVER['DOCUMENT_ROOT'] 变量设置了
if(!isset($_SERVER['DOCUMENT_ROOT']))
{
if(isset($_SERVER['SCRIPT_FILENAME']))
{
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
}
}
if(!isset($_SERVER['DOCUMENT_ROOT']))
{
if(isset($_SERVER['PATH_TRANSLATED']))
{
$_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
}
}
//现在可以使用$_SERVER['DOCUMENT_ROOT']了...
echo $_SERVER['DOCUMENT_ROOT'];
?>
本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/111058,如需转载请自行联系原作者