【发布时间】:2015-07-19 16:21:45
【问题描述】:
根据php手册:
指定 require、include、fopen()、file()、readfile() 和 file_get_contents() 函数查找文件的目录列表。格式类似于系统的 PATH 环境变量:在 Unix 中用冒号分隔的目录列表,在 Windows 中用分号分隔。
我不明白你为什么要指定目录?
例如我看到了这段代码
<?php
defined("DS") || define("DS", DIRECTORY_SEPERATOR);
defined("ROOT_DIR") || define("ROOT_DIR", realpath(dirname(__FILE__).DS."..".DS));
defined("CLASSES_DIR") || define("CLASSES_DIR", "classes");
set_include_path(implode(PATH_SEPERATOR, array(
realpath(ROOT_DIR.DS.CLASSES_DIR.DS),
get_real_path()
)));
?>
为什么要将 CLASSES_DIR 添加到包含路径?你不能已经做了类似 require("classes/example.php") 的事情吗?
【问题讨论】:
-
在执行
require("classes/example.php")时,您正在尝试获取与current working dir 相关的文件,该文件可以更改。
标签: php