Ne Kr Ne Kr - 16 days ago 5
PHP Question

includes php files from subfolder in the root

I am just setting a project up, and I cannot make my header work from a subfolder.

From subfolder/mypage.php I would like to call the resources/includes/header-test.php. It have always worked for me to do that like this:

<?php include $_SERVER['DOCUMENT_ROOT'].'/resources/includes/header-test.php'; ?>


Link to the example

Picture

but for hours I get the error on mypage.php:


Warning:
include(/customers/0/f/c/vouzalis.com/httpd.www/resources/includes/header-test.php):
failed to open stream: No such file or directory in
/customers/0/f/c/vouzalis.com/httpd.www/testProject/subfolder/mypage.php
on line 13 Warning: include(): Failed opening
'/customers/0/f/c/vouzalis.com/httpd.www/resources/includes/header-test.php'
for inclusion (include_path='.:/usr/share/php') in
/customers/0/f/c/vouzalis.com/httpd.www/testProject/subfolder/mypage.php
on line 13


I cannot solve this, so does anybody have a suggestion how I can do this?

Answer

try this:

<?php include __DIR__.'/../resources/includes/header-test.php'; ?>
Comments