thinkphp里面的路径问题_PHP教程_编程技术
在一个控制器里的方法里写下面的语句
public function test()
{
echo 'dirname(__FILE__) ' . dirname(__FILE__) . '
';
echo 'dirname(__ROOT__) ' . dirname(__ROOT__) . '
';
echo '__ROOT__ ' . __ROOT__ . '
';
//echo '__Public__ ' . __Public__ . '
';
echo '';
echo '__FILE__ ' . __FILE__ . '
';
echo '$_SERVER["PHP_SELF"]' . $_SERVER['PHP_SELF'] . '
';
echo '$_SERVER["SCRIPT_NAME"]' . $_SERVER['SCRIPT_NAME'] . '
';
echo '$_SERVER["SERVER_HOST"]' . $_SERVER['SERVER_HOST'] . '
';
echo '$_SERVER["SERVER_NAME"]' . $_SERVER['SERVER_NAME'] . '
';
echo '$_SERVER["SERVER_PROTOCOL"]' . $_SERVER['SERVER_PROTOCOL'] . '
';
echo '$_SERVER["SERVER_FILENAME"]' . $_SERVER['SCRIPT_FILENAME'] . '
';
echo dirname($_SERVER['SCRIPT_FILENAME']);
echo __DIR__;
}
浏览器访问这个方法的结果是
dirname(__FILE__) D:\WWW\tpapp\Application\Home\Controller
dirname(__ROOT__) \
__ROOT__ /tpapp
banner1.jpg__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