0

Looking for php include statement that works regardless on how nested the folders are. I use

../includes/file.php 

and that works for only one level folder. If I re-use that code at different folder levels it does not work. If I add the complete path

/account/website/protected/includes/file.php 

it does not work. If I add a partial path

/protected/includes/file.php 

it does not work. Any help is appreciated.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
mnauta
  • 11
  • 1
    If you use an absolute path, you need to use the root of your host machine, not of your project. Which is also a very bad practice! – Jerodev Jan 25 '17 at 15:41
  • @Jerodev Can you explain in short why absolute path are bad practice? Only one point given: `You have defined an constant with the base path to your project home`. `include BASE_PATH.'path/to/file.php'` – JustOnUnderMillions Jan 25 '17 at 15:46
  • Read here http://stackoverflow.com/questions/8356547/php-absolute-vs-relative-paths – JustOnUnderMillions Jan 25 '17 at 15:48
  • Also http://stackoverflow.com/questions/1755216/php-relative-and-absolute-paths look for `include(dirname(__FILE__)."/includes/myscript.php");` – JustOnUnderMillions Jan 25 '17 at 15:51

0 Answers0