无法打开流:没有这样的文件或目录,是的!

| 我在需要一些文件时遇到了问题,PHP告诉我这些文件不存在,但是当我扫描目录时会告诉我它确实存在。 我已将文件简化为“ 0”功能,但仍无法正常工作。 这是我的设置:
root/
    test.php
    test/
        test2.php
        sub/
            test3.php
test.php
echo    \'test\';
require \'test/sub/test3.php\';
test / test2.php(由于某种原因未包含的文件)
echo    \'test2\';
test / sub / test3.php
echo    \'test3\';
/* 
because we are still on test.php, the include path is the root
that means the following would work:
require \'test/test2.php\';
however I don\'t know this path in this file. (it\'s dynamic)
I thought this would work:
*/
set_include_path(dirname(__FILE__));
require \'../test2.php\';
编辑 好的,当我更改此设置时:
set_include_path(dirname(__FILE__));
require \'../test2.php\';
set_include_path(dirname(__FILE__).\"/../\"));
require \'test2.php\';
有用。 wtf PHP的? 现在这是我的输出:
testtest3
Warning: require(../test2.php) [function.require]: failed to open stream: No such file or directory in siteroot/test/sub/test3.php on line 6

Fatal error: require() [function.require]: Failed opening required \'../test2.php\' (include_path=\'siteroot/test/sub\') in siteroot/test/sub/test3.php on line 6
如果我将以下代码添加到
test3.php
echo \'<pre>\';
print_r(scandir(dirname(__FILE__).\'/../\'));
echo \'</pre>\';
我得到(如预期)以下内容:
Array
(
    [0] => .
    [1] => ..
    [2] => sub
    [3] => test2.php
)
我想我快要疯了,当我读到错误时,看上去像PHP告诉我一个文件不存在,恰好在文件所在的位置。     
已邀请:
        更改
set_include_path(dirname(__FILE__));
require \'../test2.php\';
set_include_path(dirname(__FILE__).\"/../\");
require \'test2.php\';
    
        可能是符号链接问题?尝试:
set_include_path(realpath(dirname(__FILE__))); // added realpath here
还可以尝试:
require(dirname(__FILE__) . \'/../test2.php\');
    

要回复问题请先登录注册