在一个控制器里的方法里写下面的语句
public function test()
{
echo 'dirname(__FILE__) ' . dirname(__FILE__) . '<br/>';
echo 'dirname(__ROOT__) ' . dirname(__ROOT__) . '<br/>';
echo '__ROOT__ ' . __ROOT__ . '<br/>';
//echo '__Public__ ' . __Public__ . '<br/>';
echo '<img src="' . __ROOT__ . '/Public/banner1.jpg">';
echo '__FILE__ ' . __FILE__ . '<br/>';
echo '$_SERVER["PHP_SELF"]' . $_SERVER['PHP_SELF'] . '<br/>';
echo '$_SERVER["SCRIPT_NAME"]' . $_SERVER['SCRIPT_NAME'] . '<br/>';
echo '$_SERVER["SERVER_HOST"]' . $_SERVER['SERVER_HOST'] . '<br/>';
echo '$_SERVER["SERVER_NAME"]' . $_SERVER['SERVER_NAME'] . '<br/>';
echo '$_SERVER["SERVER_PROTOCOL"]' . $_SERVER['SERVER_PROTOCOL'] . '<br/>';
echo '$_SERVER["SERVER_FILENAME"]' . $_SERVER['SCRIPT_FILENAME'] . '<br/>';
echo dirname($_SERVER['SCRIPT_FILENAME']);
echo __DIR__;
}
浏览器访问这个方法的结果是
dirname(__FILE__) D:\WWW\tpapp\Application\Home\Controller
dirname(__ROOT__) \
__ROOT__ /tpapp
__FILE__ D:\WWW\tpapp\Application\Home\Controller\ApiController.class.php
$_SERVER["PHP_SELF"]/tpapp/index.php/home/api/test
$_SERVER["SCRIPT_NAME"]/tpapp/index.php
$_SERVER["SERVER_HOST"]
$_SERVER["SERVER_NAME"]localhost
$_SERVER["SERVER_PROTOCOL"]HTTP/1.1
$_SERVER["SERVER_FILENAME"]D:/WWW/tpapp/index.php
D:/WWW/tpappD:\WWW\tpapp\Application\Home\Controller
本文转自 陈小龙哈 51CTO博客,原文链接:http://blog.51cto.com/chenxiaolong/1714911