包括在PHP中 [英] includes in php
问题描述
我在项目中包含了很多页面,我遇到包含内部路径不正确的问题,有没有办法从root包含文件,
我试着这样做
I include many pages inside each other in my project, I face problem of incorrect paths inside the include, is there any way to include the file from the root, I try to make like this
require_once("$_SERVER['DOCUMENT_ROOT']/crm/includes/opendb.php");
require_once("./includes/opendb.php");
require_once("../includes/opendb.php");
require_once("includes/opendb.php");
并且所有包含文件时出错,任何建议都是PLZ?
and all makes error in includeing the file, any suggestion plz?
编辑
我有2个文件夹,控制器和包含,在控制器内我从include文件夹中调用opendb.php ,我在下面的答案中证明了这一点
I have 2 folders, controllers and includes, inside the controller I call opendb.php from includes folder, I make as demonstrated in an answer below
set_include_path('../includes/');
include 'opendb.php';
和
set_include_path('includes/');
include 'opendb.php';
但同样的错误
Warning: include(opendb.php) [function.include]: failed to open stream: No such file or directory in C:\AppServ\www\crm\controllers\Customer.controller.php on line
推荐答案
$ _SERVER ['DOCUMENT_ROOT'] / crm / includes / opendb.php
不正确:你不能在双引号内的数组键周围使用撇号。请尝试以下方法之一:
"$_SERVER['DOCUMENT_ROOT']/crm/includes/opendb.php"
is incorrect: you can't use apostrophes around array keys inside double quotes. Try one of these:
require_once( $_SERVER['DOCUMENT_ROOT']."/crm/includes/opendb.php" );
require_once( "$_SERVER[DOCUMENT_ROOT]/crm/includes/opendb.php" );
require_once( "{$_SERVER['DOCUMENT_ROOT']}/crm/includes/opendb.php" );
这篇关于包括在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!