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?

5
  • 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. Commented Jan 19, 2012 at 2:49
  • 1
    Or you use a MVC pattern (or a framework) Commented Jan 19, 2012 at 2:50
  • 2
    @RPM And how is an MVC framework going to help a situation where existing code includes files it cannot locate? Commented Jan 19, 2012 at 2: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. Commented Jan 19, 2012 at 2:51
  • 1
    I assume the included includes are linked relatively rather than absolutely... Commented Jan 19, 2012 at 2:59

2 Answers 2

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().

https://www.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');

Sign up to request clarification or add additional context in comments.

1 Comment

Someone told me using <base href="/"> would be the right way to go. Would you recommend this?
0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.