php 无法打开流:中没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7794656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
failed to open stream: No such file or directory in
提问by Dmitry Makovetskiyd
> Warning: include_once(/PoliticalForum/headerSite.php) [function.include-once]: failed to open stream: No such file or
> directory in C:\xampp\htdocs\PoliticalForum\mainHome.php on line 16
>
> Warning: include_once() [function.include]: Failed opening
> '/PoliticalForum/headerSite.php' for inclusion
> (include_path='.;C:\xampp\php\PEAR') in
> C:\xampp\htdocs\PoliticalForum\mainHome.php on line 16
Why do I get that Error when I use include_once:
为什么在使用 include_once 时会出现该错误:
include_once("/PoliticalForum/headerSite.php");
采纳答案by Daren Chandisingh
It's because you have included a leading /
in your file path. The /
makes it start at the top of your filesystem. Note: filesystempath, not Web site path (you're not accessing it over HTTP). You can use a relativepath with include_once
(one that doesn't start with a leading /
).
这是因为您/
在文件路径中包含了前导。这/
使它从文件系统的顶部开始。注意:文件系统路径,而不是网站路径(您不是通过 HTTP 访问它)。您可以使用相对路径 with include_once
(不以前导开头的路径/
)。
You can change it to this:
您可以将其更改为:
include_once 'headerSite.php';
That will look first in the same directory as the file that's including it (i.e. C:\xampp\htdocs\PoliticalForum\
in your example.
这将首先在与包含它的文件相同的目录中查找(即C:\xampp\htdocs\PoliticalForum\
在您的示例中。
回答by Pekka
include() needs a full file path, relative to the file system's root directory.
include() 需要一个完整的文件路径,相对于文件系统的根目录。
This should work:
这应该有效:
include_once("C:/xampp/htdocs/PoliticalForum/headerSite.php");
回答by IT Vlogs
you can use:
您可以使用:
define("PATH_ROOT", dirname(__FILE__));
include_once PATH_ROOT . "/PoliticalForum/headerSite.php";
回答by Ashish v
Failed to open stream error occurs because the given path is wrong such as:
无法打开流错误发生,因为给定的路径是错误的,例如:
$uploadedFile->saveAs(Yii::app()->request->baseUrl.'/images/'.$model->user_photo);
It will give an error if the images folder will not allow you to store images, be sure your folder is readable
如果图像文件夹不允许您存储图像,则会出现错误,请确保您的文件夹可读