Phil Penny
Phil Penny

Reputation: 123

php include header and footer in complex file structure

I have to following file structure:

ROOT
index.html
    INCLUDES
        header.html
        footer.html
    FOLDER1
        FOLDER2
            FOLDER3
                FOLDER4
                    file.php

When I use

include('includes/header.html');

in my index.html file, the header is pulled in correctly.

However, I cannot get it to traverse the file structure from file.php. I have tried the following:

include('../../../../includes/header.html');

Can you spot what I am doing wrong? Is there a way to do it so I can just specify

include('includes/header.html');

regardless of which page I am on?

Upvotes: 0

Views: 362

Answers (3)

Ankur Saxena
Ankur Saxena

Reputation: 639

$var=(dirname(dirname(__FILE__)).'/');
    require_once($var.'header.html');
echo $var;//you find how many directory back you are 

Upvotes: 0

FloydThreepwood
FloydThreepwood

Reputation: 1585

The default method to do this is to adjust the include_path variable from php, so any file can include your library folder, regardless of the filesystem position.

Upvotes: 0

user1909426
user1909426

Reputation: 1668

include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.html');

Upvotes: 3

Related Questions