php include file that has includes

2019-02-27 20:04发布

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?

2条回答
Bombasti
2楼-- · 2019-02-27 20:34

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

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

查看更多
做自己的国王
3楼-- · 2019-02-27 20:46

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');

查看更多
登录 后发表回答