thinkphp裡面的路徑問題
在一個控制器裡的方法裡寫下面的語句
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
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