PHP:包含相对于调用文件而不是根文件的文件?
好吧,假设我在同一目录中有一个名为 fileA.php
的文件,我还有另一个名为 fileB.php
的文件,
所以在 fileA 中有这个 require_once('fileB. php')
请注意,我没有指定文件路径,因为这两个文件位于同一目录中。
现在,如果 fileA 包含到位于其他位置的另一个文件中,则它无法包含 fileB,因为父文件(包含 fileA 的文件)与 fileB 不在同一目录中。
那么如何才能使 fileA 加载 fileB 无论 fileA 包含在何处?
这有道理吗?
谢谢!!
OK say I have a file called fileA.php
in the same directory I have another file called fileB.php
so inside fileA there is this require_once('fileB.php')
notice I did not specify a file path because both files are in the same directory.
Now if fileA is included into another file that is located somewhere else, it fails to include fileB because the parent file (the file that included fileA) is not in the same directory as fileB.
So how can I make it so that fileA loads fileB no matter where fileA is included into?
Does that make sense?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设 fileA.php 和 fileB.php 都保证位于同一目录中,这应该可以工作:
Assuming both fileA.php and fileB.php are guaranteed to be in the same directory, this should work:
http://php.net/manual/en/function.include.php# 78716
您可以将包含根设置为您的网站根。
http://php.net/manual/en/function.include.php#78716
You can set the include root to your website root.