Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

>     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");
like image 675
Dmitry Makovetskiyd Avatar asked Oct 17 '11 13:10

Dmitry Makovetskiyd


3 Answers

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.

like image 67
Daren Chandisingh Avatar answered Nov 12 '22 06:11

Daren Chandisingh


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");
like image 36
Pekka Avatar answered Nov 12 '22 05:11

Pekka


you can use:

define("PATH_ROOT", dirname(__FILE__));
include_once PATH_ROOT . "/PoliticalForum/headerSite.php";
like image 4
IT Vlogs Avatar answered Nov 12 '22 05:11

IT Vlogs