【ERROR_3】关于路径:绝对+相对路径混写的情况

来源:互联网 发布:兼职美工一张图多少钱 编辑:程序博客网 时间:2024/06/05 15:02

近日在书中看到如下路径的写法,不太理解:

$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!打开成功

 

 

说明: ../ 这种写法不安全,建议少采用!

原创粉丝点击