Reputation: 8103
I try to include my files, but for some reason I can't...
Here is my structure:
On index.php
, there is a include_once('includes/php/inc.php');
. The inc.php
contains these lines:
// Required classes
require_once '../classes/cl_calendar.php';
Perfect legitimate I think, but for some reason all I get is this error:
Warning: require_once(../classes/cl_calendar.php): failed to open stream: No such file or directory in /customers/xxx/xxx/httpd.www/new/extra/php/inc.php on line 14 Fatal error: require_once(): Failed opening required '../classes/cl_calendar.php' (include_path='.:/usr/share/php') in /customers/xxx/xxx/httpd.www/new/extra/php/inc.php on line 14
What makes this error to be displayed and how do I get rid of it?
Upvotes: 1
Views: 8292
Reputation: 40685
The correct path is includes/classes/file.php. Why the ..? This would lead you one level over the root.
The reason for that is that even though the relative relation of the two included files may be a different one, you're including it from the index file and therefore the path has to be relative to the index file.
Upvotes: 1
Reputation: 736
Just Drag and drop this page cl_calendar.php to your index.php page, and and this will showing as href link then just copy full href path and paste it as it is in include.
or try this one
require_once(/../classes/cl_calendar.php);
Upvotes: 0
Reputation: 9299
When you include a php file from another, it's just like taking the contents of that file and placing it in your initial (index.php
) file. So, when you to require more files from the inc.php
file it's being based on the path of the initial file. Try setting a base path in your index.php
file and use that in your inc.php
file. Try
// index.php
$base = "/var/www/htdocs/";
// or something like dirname(__FILE__) if it may change
include_once($base.'includes/php/inc.php');
// inc.php
require_once($base.'classes/cl_calendar.php');
Upvotes: 1