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

Kok*_*kos 8 php require

我有一个问题需要一些文件,PHP告诉我这些文件不存在,但当我扫描目录它告诉我它确实存在.

我已经将文件简化为require功能,但它仍然无法正常工作.

这是我的设置:

root/
    test.php
    test/
        test2.php
        sub/
            test3.php
Run Code Online (Sandbox Code Playgroud)

test.php的

echo    'test';
require 'test/sub/test3.php';
Run Code Online (Sandbox Code Playgroud)

test/test2.php(由于某种原因未包含的文件)

echo    'test2';
Run Code Online (Sandbox Code Playgroud)

测试/分/ 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';
Run Code Online (Sandbox Code Playgroud)

编辑

好的,当我改变这个:

set_include_path(dirname(__FILE__));
require '../test2.php';
Run Code Online (Sandbox Code Playgroud)

set_include_path(dirname(__FILE__)."/../"));
require 'test2.php';
Run Code Online (Sandbox Code Playgroud)

有用.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
Run Code Online (Sandbox Code Playgroud)

如果我将以下代码添加到test3.php:

echo '<pre>';
print_r(scandir(dirname(__FILE__).'/../'));
echo '</pre>';
Run Code Online (Sandbox Code Playgroud)

我得到(如预期)以下内容:

Array
(
    [0] => .
    [1] => ..
    [2] => sub
    [3] => test2.php
)
Run Code Online (Sandbox Code Playgroud)

我想我会疯了,当我读到它看起来错误时,就像PHP告诉我文件不存在,恰好在文件所在的位置.

gen*_*sis 7

更改

set_include_path(dirname(__FILE__));
require '../test2.php';
Run Code Online (Sandbox Code Playgroud)

set_include_path(dirname(__FILE__)."/../");
require 'test2.php';
Run Code Online (Sandbox Code Playgroud)