Here’s a sample file structure:
page.php
db.php
folder1/subpage.php
folder2/fn.php
page.php
require_once('folder2/fn.php');
folder1/subpage.php
require_once('../folder2/fn.php');
folder2/fn.php – requires database connection
require_once('../db.php');
/* then gets info from database */
Basically, fn.php contains database functions to get/set information. It requires db.php, which is database connection file. This code works in subpage.php, but not in page.php (getting “failed to open stream: No such file or directory in …” error).
Is there a way (using relative referencing), so that it works in all files no matter of directory level?
Thanks for your help!
I always use the absolute path to the include. There are a couple ways to do this, this command will return the absolute path
no matter where the file is php will have the absolute path.