将一个PHP文件包含到另一个文件中 [英] Include one PHP file into another

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

问题描述

我需要将一个PHP文件包含到另一个文件中.不过,需要包含的PHP文件位于单独的目录中.设置方法如下:

I need to include one PHP file into another. The PHP file that needs to be included sits in a separate directory though. This is how it is set up:

folder1/global-functions.php
folder1/folder2/functions.php

我需要在"functions.php"中包含"global-functions.php"

I need to include the 'global-functions.php' in the 'functions.php'

我尝试过:

<?php include("../global-functions.php"); ?>

但是这不起作用.它返回此错误消息:

But this will not work. It returns this error message:

警告:include(../global-functions.php)[function.include]:无法打开流:/home/user/public_html/wp-content/themes/folder1/folder2/中没有此类文件或目录第2行上的custom_functions.php

Warning: include(../global-functions.php) [function.include]: failed to open stream: No such file or directory in /home/user/public_html/wp-content/themes/folder1/folder2/custom_functions.php on line 2

警告:include()[function.include]:无法打开要包含的'../global-functions.php'(include_path ='.:/usr/lib/php:/usr/local/lib/php' )在第2行的/home/user/public_html/wp-content/themes/folder1/folder2/custom_functions.php中

Warning: include() [function.include]: Failed opening '../global-functions.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/user/public_html/wp-content/themes/folder1/folder2/custom_functions.php on line 2

推荐答案

尝试包含具有绝对路径的文件:类似这样的东西:

Try including the file with an absolute path: something like this:

<?php include ($_SERVER['DOCUMENT_ROOT']."/folder1/global-functions.php");?>

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

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