近日在书中看到如下路径的写法,不太理解:
$document_root=$_SERVER['DOCUMENT_ROOT'];
$f=fopen("$document_root/../orders/orders.txt","rb");
今日弄清楚了,这是php绝对路径与相对路径混写的一种方式,它表示 $document_root上一级目录下的orders/orders.txt
例如:若$document_root的值为:D:/usr/apache/htdocs ,则:$document_root/../orders/orders.txt 表示的路径是:
D:/usr/apache/orders/orders.txt
测试代码:(注:D:/usr/apache/orders/orders.txt 为存在文件)
输出结果:
D:/usr/apache/htdocs
success!打开成功
说明: ../ 这种写法不安全,建议少采用!