PHP中的require_once [英] require_once in php

查看:73
本文介绍了PHP中的require_once的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php文件,该文件具有require_once语句(?),然后将该文件包含在其他2个php文件中,一个php文件位于子目录中,因此布局如下("file1"和"file2"包括文件"included",其中"require_onces"是"required")#

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

如何从"included"文件中引用"required"文件,以便它在file1和file2中都可以使用?

How can I reference the "required" file from the "included" file so that it will work from both file1 and file2?

推荐答案

始终使用绝对路径

$_SERVER['DOCUMENT_ROOT']."/included";

$_SERVER['DOCUMENT_ROOT']."/subfolder2/required";

可以在任何地方工作

这篇关于PHP中的require_once的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆