Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php nested include behavior

In many places in my code, I do things like:

file1.php:
<?php
include('../file2.php');

file2.php:
<?php
include('anotherdirectory/file3.php');

Depending on the server or settings I try this on, it either sets the relative paths from the "includer" or from the "includee". This is really confusing. So file1 might try to include "../anotherdirectory/file3.php" or it might try "anotherdirectory/file3.php".

What settings dictate this behavior? I want to have control over this...

like image 245
Nathan H Avatar asked May 18 '10 18:05

Nathan H


1 Answers

In cases when I need to use relative paths I use the following syntax:

include (realpath(dirname(__FILE__)."/another_folder/myfile.php"));
like image 198
a1ex07 Avatar answered Sep 28 '22 23:09

a1ex07