如何正確使用$_SERVER['DOCUMENT_ROOT']識別該路徑的文件

 

echo $_SERVER['DOCUMENT_ROOT'];

這時輸出當前文件所在的路徑 D:/phpStudy/WWW/study/php&mysql php

 $_SERVER['DOCUMENT_ROOT']/orders.txt 這時候覺得輸出的路徑爲 D:/phpStudy/WWW/study/php&mysql/orders.txt mysql

可是經過echo 輸出的爲結果爲:sql

Notice: Use of undefined constant orders - assumed 'orders' in D:\phpStudy\WWW\study\php&mysql\test.php on line 9

Warning: Division by zero in D:\phpStudy\WWW\study\php&mysql\test.php on line 9

Notice: Use of undefined constant txt - assumed 'txt' in D:\phpStudy\WWW\study\php&mysql\test.php on line 9
txt

咱們給 orders.txt 兩邊加上雙引號試試,變成 spa

$_SERVER['DOCUMENT_ROOT'].」/orders.txt「 

這時才能正確識別orders.txt的地址code

 D:/phpStudy/WWW/study/php&mysql/orders.txt blog

還有一種方式就是給 $_SERVER['DOCUMENT_ROOT'] 兩邊加上大括號,而後總的路徑打上雙引號io

"{$_SERVER['DOCUMENT_ROOT']}/orders.txt"

這樣也能正確輸出orders.txt的地址class

相關文章
相關標籤/搜索