Becky
Becky

Reputation: 2289

Getting from a sub folder to the root failing

I am trying to include a header/footer with php's include_once. I did not have any trouble until I created a sub-folder called, "states". I tried to include include_once("header.php"); and it is failing. I know it is because it is not in the same directory, so I tried include_once("/header.php"); and that did not work. I also tried doing this:

include_once("header/states.php");

include_once("header/.php");

What am I doing wrong for this to not get to the correct directory? I am trying to organize a bunch of files and I want to do this the correct way, so any help appreciated.

enter image description here

enter image description here

Upvotes: 0

Views: 24

Answers (1)

Hektor
Hektor

Reputation: 1945

Use ./ to reference the current directory:

        include_once("./states/header.php");

That's assuming the file you are referencing from is in the directory shown. If it's in another directory ( like _notes ) then the directory one level up can be referenced by ../, thus:

        include_once("../states/header.php");

Upvotes: 1

Related Questions