3

I am working on a site and have been asked to include files that are sitting in a folder above my php scripts. Problem is those php files I have been asked to include, have includes in them. And thus the files they refer to cannot be found when calling my php pages.

What is the best way to handle this situation?

user1157576
  • 47
  • 1
  • 3
  • 2
    You need to locate the files they attempt to include, and then add that path to `include_path` in php.ini OR modify the files which include them to point to the correct paths. – Michael Berkowski Jan 19 '12 at 02:49
  • 1
    Or you use a MVC pattern (or a framework) – Ryan Jan 19 '12 at 02:50
  • 2
    @RPM And how is an MVC framework going to help a situation where existing code includes files it cannot locate? – Michael Berkowski Jan 19 '12 at 02:51
  • 2
    That is not a problem per se, included includes are rather normal. Show us details about *why* the included includes don't work. – deceze Jan 19 '12 at 02:51
  • 1
    I assume the included includes are linked relatively rather than absolutely... – Erik Jan 19 '12 at 02:59

2 Answers2

1

When including a file from folder B to folder A, the B script acts like it was stored in A. Either change your pointer paths or chdir().

http://se2.php.net/manual/en/function.chdir.php

Or use full paths rather than local. Such as

$home = '/home/user/path/to/root/;

Include_once($home .'folderb/script.php');

tim
  • 2,530
  • 3
  • 26
  • 45
0

Server side: include($_SERVER['DOCUMENT_ROOT'] . 'subfolder/file.php');

Means from the client side: {http://www.domain.com}/subfolder/file.php

tim
  • 2,530
  • 3
  • 26
  • 45