无法打开流:没有这样的文件或目录,是的! [英] Failed to open stream: No such file or directory, yes there is!

查看:314
本文介绍了无法打开流:没有这样的文件或目录,是的!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在需要一些文件时遇到了问题,PHP告诉我这些文件不存在,但是当我扫描目录时会告诉我它确实存在.

I've got a problem with requiring some files, PHP is telling me these files do not exist, but when I scan the directory it tells me it does exist.

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

I've simplified the files to the require functionality, and it's still not working.

这是我的设置:

root/
    test.php
    test/
        test2.php
        sub/
            test3.php

test.php

echo    'test';
require 'test/sub/test3.php';

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

test/test2.php (the file that for some reason doesn't get included)

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';


编辑

好的,当我更改此设置时:

Okay, when I changed this:

set_include_path(dirname(__FILE__));
require '../test2.php';

set_include_path(dirname(__FILE__)."/../"));
require 'test2.php';

有效. wtf php吗?

it works. 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:

If I add the following code to test3.php:

echo '<pre>';
print_r(scandir(dirname(__FILE__).'/../'));
echo '</pre>';

(预期)我得到以下信息:

I get (as expected) the following:

Array
(
    [0] => .
    [1] => ..
    [2] => sub
    [3] => test2.php
)

我想我快要疯了,当我读到错误时,似乎PHP告诉我一个文件不存在,确切地在文件所在的位置. >

I think I'm going insane, when I read the errors it looks to me like PHP is telling me a file doesn't exist, exactly in the place where the file is.

推荐答案

更改

set_include_path(dirname(__FILE__));
require '../test2.php';

set_include_path(dirname(__FILE__)."/../");
require 'test2.php';

这篇关于无法打开流:没有这样的文件或目录,是的!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆