php include_once not working
26,434
Solution 1
In Form.php
use
include_once dirname(__FILE__) . '/../GridView/GridView.php';
This creates an absolute path, but relative to the file, where its called from.
Solution 2
It can't find the file.
You should use a full path, like /Php/Controls/GridView/GridView.php
instead of a relative one.
Solution 3
Try this:
include_once './php/Controls/GridView/GridView.php';
Solution 4
Hope I'm not too late on this one but I thought this might be what you're looking for:
include_once realpath(dirname(__FILE__)."/../GridView/GridView.php");
Using realpath()
allows you to include files even from outside your server document root directory.
Related videos on Youtube
Author by
Jean-Philippe Leclerc
Updated on November 20, 2020Comments
-
Jean-Philippe Leclerc over 3 years
What would be the reasons of a non working include_once?
Here's my folder hierarchy:
/Php/Controls/GridView/GridView.php /Php/Controls/Form/Form.php
In "Form.php":
include_once '../GridView/GridView.php';
I'm getting this error:
Warning: include_once(../GridView/GridView.php) [function.include-once]: failed to open stream: No such file or directory in ...Form.php on line 4 Warning: include_once() [function.include]: Failed opening '../GridView/GridView.php' for inclusion (include_path='.;C:\php\pear') in ...Form.php on line 4
Please tell me if you want more information.
-
KingCrunch about 13 yearsThe include path is only used, if its a "real" relative path (does not start with
/
or.
) , but with.
or..
it always creates the pathes from the current workdir (see @svens comment)
-
-
Willem Van Onsem over 9 yearsA problem with an absolute path is that when one decides to move/copy the website, many things will get broken...