我最近为api制作了一个API我已经创建了一个子域但是它打破了我的php文件包含
include $_SERVER['DOCUMENT_ROOT'].'/core/init.php';
现在我使用的子域是api.website.com,当我尝试包含它给出子域的根时,我需要包含来自website.com的东西,
总结当我尝试包含init.php时,我得到了
Warning: include(/home/website/public_html/API/core/init.php): failed to open stream: No such file or directory in /home/website/public_html/api/apex/getusers.php on line 2
当我真的需要的时候
Warning: include(/home/website/public_html/core/init.php): failed to open stream: No such file or directory in /home/website/public_html/api/apex/getusers.php on line 2
如果需要,我为我的语法道歉。
将包含路径更改为
include ("../../core/init.php");
将解决您的问题。但是,这不是推荐的方法。
你应该考虑使用像composer这样的依赖管理器。 (https://getcomposer.org/)。然后,您包含的文件将始终位于类似的目录下
/home/website/public_html/vendor/core
如果/ home / website / public_html / core中的文件发生变化,您的应用程序破坏的可能性就会降低。
这应该工作。
include("../core/init.php");
使用以下代码
include_once $_SERVER['DOCUMENT_ROOT'] . '/../core/init.php';
访问https://developer.hyvor.com/php/including-files-in-root-with-subdomain.php了解更多信息。