我有一个文件 Profile.php
,其中包含 Profile_Control.php
并且 profile_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
在 Upload.php 中:
include_once("../../Control/Profile_Control.php");
在 Profile.php 中:
include_once("../Control/Profile_Control.php");
在 Profile_Control.php 中:
include_once("../Model/Profile_Model.php");
文档结构:
+-Control/
| |
| +---- Profile_Control.php
|
+-Model/
| |
| +---- Profile_Model.php
|
+-Other/
|
+-- Upload/
|
+---- Upload.php
最佳答案
与其使用相对路径 (../
),不如尝试提供相对于 $_SERVER['DOCUMENT_ROOT']
位置的绝对路径。我通常定义一个常量来帮助提高可读性——
define('_root',$_SERVER['DOCUMENT_ROOT']);
include(_root.'/Control/Profile_Control.php');
现在您可以在每个要包含 Profile_Control.php
的文件中放置相同的代码行。
user1280616在包含文件之前测试文件的存在也提出了一个有效的观点。也许您也应该考虑实现它。
关于php - 无法打开没有此类文件或目录的流。 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12445241/