dirname(__file__) 函数返回的是脚本所在的路径。
比如文件 index.php 包含如下内容:
我做的测试得到结果: e:\wamp\www\test
如果index.php被其他目录里的test.php文件require 或者 include 去引用的话。 变量$basedir 的内容还是index.php所在的那个文件夹的路径;而不是变成test.php文件所在的目录。
dirname(dirname(__file__));得到的是文件上一层目录名。
扩展知识点:
directory_separator:php的内置变量directory_separator是一个显示系统分隔符的命令,directory_separator是php的内部常量,不需要任何定义与包含即可直接使用。
此php内置命令,在windows上返回\,而在linux或者类unix上返回/,就是这么个区别,通常在定义包含文件路径或者上传保存目录的时候会用到。
例:
//phpcms框架路径
define('pc_path', dirname(__file__).directory_separator);
