我有一个文件结构如下:require_once不工作(相对路径)
>project
>admin
>classes
>class_main.php
>templates
>foot.php
在class_main.php,我试图用require_once
要求相同的文件,这取决于用户在哪里(也就是说,如果用户在我的类的__destruct函数内部,那么该用户位于管理目录中,即require_once "../templates/foot.php"
,否则为require_once "./templates/foot.php"
)。
我的问题是,无论我怎么努力,我总是收到相同的错误:
Warning: require_once(C:\wamp\www\project\classes/templates/foot.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\project\classes\class_main.php on line 22
我曾尝试:用require_once作为一个功能
- 使用
dirname(__FILE__)
和__DIR__
- 使用
\
和\\
而不是/
我该怎么做?
此刻的__destruct功能的完整代码:
function __destruct()
{
if($this->admtrim($_SERVER['PHP_SELF']) == 'admin')
{
require_once "../templates/foot.php";
}
else
{
require_once './templates/foot.php';
}
}
要澄清,这个脚本位于C:\wamp\www\project\classes\class_main.php
,我想包括文件位于C:\wamp\www\project\templates\foot.php
。
如果您想获得一些有用的答案,请使用'require_once'发布实际代码。 – 2013-03-05 07:00:05