failed to open stream: No such file or directory in [duplicate]
Asked Answered
D

4

33
>     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");
Dishearten answered 17/10, 2011 at 13:43 Comment(1)
One often runs into this error, and to quickly troubleshoot it, follow these steps : https://mcmap.net/q/46525/-php-failed-to-open-stream-no-such-file-or-directoryChlori
M
31

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.

Malcah answered 17/10, 2011 at 13:54 Comment(3)
I have started a troubleshooting checklist for this frequent error here : https://mcmap.net/q/46525/-php-failed-to-open-stream-no-such-file-or-directoryChlori
what should be the path if i use LAMP in ubuntu ?Universalism
if you use composer , don't forget composer dump-autoload specially if you rename any classEmploy
C
9

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");
Collyer answered 17/10, 2011 at 13:44 Comment(2)
...or he could just do include_once("headerSite.php"); which would make the code more portable...Nole
I have started a troubleshooting checklist for this frequent error here : https://mcmap.net/q/46525/-php-failed-to-open-stream-no-such-file-or-directoryChlori
P
4

you can use:

define("PATH_ROOT", dirname(__FILE__));
include_once PATH_ROOT . "/PoliticalForum/headerSite.php";
Pendley answered 26/1, 2016 at 3:58 Comment(0)
C
0

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

Churchlike answered 19/3, 2013 at 5:2 Comment(1)
I have started a troubleshooting checklist for this frequent error here : https://mcmap.net/q/46525/-php-failed-to-open-stream-no-such-file-or-directoryChlori

© 2022 - 2024 — McMap. All rights reserved.