无法打开流没有这样的文件或目录.PHP

Mj1*_*992 3 php php-include

我有一个Profile.php包含Profile_Control.phpprofile_control包含的文件Profile_Model.php.在这里,每件事情都很好.

我有另一个脚本命名,Upload.php从哪个数据上传.这个Upload.php还包括Profile_Control.php并且如你所知Profile_Control包含Profile_Model.php.现在我不知道它为什么会出现这样的错误.当Profile.php加载它工作正常但是当我上传数据时它说

Warning: include(../Model/Profile_Model.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\php\gagster\Control\Profile_Control.php on line 4
Run Code Online (Sandbox Code Playgroud)

在Upload.php中:

include_once("../../Control/Profile_Control.php");
Run Code Online (Sandbox Code Playgroud)

在Profile.php中:

include_once("../Control/Profile_Control.php");
Run Code Online (Sandbox Code Playgroud)

在Profile_Control.php中:

include_once("../Model/Profile_Model.php");
Run Code Online (Sandbox Code Playgroud)

文件结构:

 +-Control/
 |  |    
 |  +---- Profile_Control.php
 |
 +-Model/
 |  |
 |  +---- Profile_Model.php
 |
 +-Other/
    |
    +-- Upload/
           |
           +---- Upload.php
Run Code Online (Sandbox Code Playgroud)

Lix*_*Lix 8

而不是使用相对路径(../),为什么不尝试给出相对于您的$_SERVER['DOCUMENT_ROOT']位置的绝对路径.我通常定义一个常量来帮助提高可读性 -

define('_root',$_SERVER['DOCUMENT_ROOT']);

include(_root.'/Control/Profile_Control.php');
Run Code Online (Sandbox Code Playgroud)

现在,您可以在要包含的每个文件中放置相同的代码行Profile_Control.php.

user1280616在包含文件之前测试文件的存在性也是有效的.也许您应该考虑实施它.