Reputation: 6763
i receive this PHP Error whenever i try to include a php file in my index.php:
No such file or directory
At first i include this file at the beginning of the index.php: require_once("../resources/engine/settings.php");
And i get no error, but when i include the header file with require_once($TEMPLATES."/header.php");
I get that error.
$TEMPLATES is a variable that's declared in settings.php (that is included correctly into index.php).
This is settings.php:
<?php
$BASEURL = "http://localhost/webname";
$CSSFolder = $BASEURL."/public/css";
$CSS = $CSSFolder."/style.css";
$IMGFolder = $BASEURL."/public/img";
$ROOT = $_SERVER["DOCUMENT_ROOT"]."/webname";
$TEMPLATES = $ROOT."/resources/templates";
$ENGINE = $ROOT."/resources/engine";
?>
Upvotes: 1
Views: 13398
Reputation: 2045
And yes, using of dirname(__FILE__)
is much better, because your site root could not always be the same as the server's DOCUMENT_ROOT.
Also on some configs nice to use als realpath()
to resolve some symlinks.
Upvotes: 0
Reputation: 8101
Instead of using $_SERVER['DOCUMENT_ROOT']
, i always use dirname to get the root path defined, and id suggest you to use that also. If you use this all over the place, you'll faster get rid of all the path traversing confusion that can arise with it.
I find it easier to work with, like this
$ROOT = dirname(__FILE__)."/webname";
Although they seem to return the same, using DOCUMENT_ROOT
returns the absolute path of where the script is executing, whereas the dirname
call is absolute to where the file is located physically.
Now to address your question:
An easy way to debug includes like this is to actually just print out the path, which would be print $TEMPLATES."/header.php"
and check whether that is what you expect it to be, if not, then correct it.
Upvotes: 3