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

发布于 2024-12-10 11:58:59 字数 566 浏览 1 评论 0原文

>     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

为什么当我使用 include_once 时会出现该错误:

   include_once("/PoliticalForum/headerSite.php");
>     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("/PoliticalForum/headerSite.php");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

枯叶蝶 2024-12-17 11:58:59

这是因为您在文件路径中包含了前导 // 使其从文件系统的顶部开始。注意:文件系统路径,而不是网站路径(您不是通过 HTTP 访问它)。您可以将相对路径与include_once(不以前导/ 开头的路径)结合使用。

您可以将其更改为:

include_once 'headerSite.php';

这将首先在包含它的文件所在的目录中查找(即示例中的 C:\xampp\htdocs\PoliticalForum\ )。

It's because you have included a leading / in your file path. The / makes it start at the top of your filesystem. Note: filesystem path, not Web site path (you're not accessing it over HTTP). You can use a relative path with include_once (one that doesn't start with a leading /).

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.

乱了心跳 2024-12-17 11:58:59

include() 需要相对于文件系统根目录的完整文件路径。

这应该有效:

 include_once("C:/xampp/htdocs/PoliticalForum/headerSite.php");

include() needs a full file path, relative to the file system's root directory.

This should work:

 include_once("C:/xampp/htdocs/PoliticalForum/headerSite.php");
庆幸我还是我 2024-12-17 11:58:59

你可以使用:

define("PATH_ROOT", dirname(__FILE__));
include_once PATH_ROOT . "/PoliticalForum/headerSite.php";

you can use:

define("PATH_ROOT", dirname(__FILE__));
include_once PATH_ROOT . "/PoliticalForum/headerSite.php";
久光 2024-12-17 11:58:59

由于给定的路径错误而发生无法打开流错误,例如:

$uploadedFile->saveAs(Yii::app()->request->baseUrl.'/images/'.$model->user_photo);

如果图像文件夹不允许您存储图像,则会出现错误,
确保您的文件夹可读

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文