日期:2014-05-17  浏览次数:20451 次

得到服务器绝对路径的PHP代码


echo "__FILE__  : <p style='color:red'>".__FILE__."</p>";
echo "dirname(__FILE__)  : <p style='color:red'>".dirname(__FILE__)."</p>";


echo "\$_SERVER['DOCUMENT_ROOT']:<p style='color:red'>".$_SERVER['DOCUMENT_ROOT']."</p>";
echo "\$_SERVER['PHP_SELF'] : <p style='color:red'>".$_SERVER['PHP_SELF']."</p>";
echo "dirname(\$_SERVER['PHP_SELF']) :  <p style='color:red'>" .dirname($_SERVER['PHP_SELF'])."</p>";
echo "<p style='color:red'>".$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."</p>";

echo "realpath('./') : <p style='color:red'>".realpath('./')."</p>";


$pathInfo = pathinfo(__FILE__);
echo "pathinfo(__FILE__,PATHINFO_DIRNAME):<p style='color:red'>".$pathInfo[dirname]."</p>";
echo "pathinfo(__FILE__,PATHINFO_BASENAME):<p style='color:red'>".$pathInfo[basename]."</p>";
echo "pathinfo(__FILE__,PATHINFO_EXTENSION]):<p style='color:red'>".$pathInfo[extension]."</p>";

echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";