PHP 中的 require_once
我有一个 php 文件,其中有一个 require_once 语句(?),然后该文件包含在另外 2 个 php 文件中,一个 php 文件位于子目录中,因此布局如下(“file1”和“file2”包含该文件"included" which require_onces the "required")#
L--subfolder1
| L--file1
L--subfolder2
| L--required
L--file2
L--included
如何从“included”文件中引用“required”文件,以便它可以在 file1 和 file2 中工作?
I have a php file which has a require_once Statement (?) this file is then in included in 2 other php files, one php file is in a sub directory so the layout is like this ("file1" and "file2" include the file "included" which require_onces the "required")#
L--subfolder1
| L--file1
L--subfolder2
| L--required
L--file2
L--included
How can I reference the "required" file from the "included" file so that it will work from both file1 and file2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
始终使用绝对路径
或
可以在任何地方工作
always use absolute path
or
would work from anywhere
您必须使用绝对路径才能从任何地方请求具有相同代码的文件。
You have to use absolute path to be able to require the file with the same code from anywhere.
您可以将 dirname() 与 __FILE__ 常量结合使用。 (如果我理解正确的话,您会从两个脚本中包含“包含”文件,然后“包含”包含一些文件?)
包含(.php):
You can use dirname() in combination with the
__FILE__
constant. (If I understand you correctly you're including the file 'included' from both scripts and 'included' then includes some files?)included(.php):