Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
服务器根目录中的php include()?_Php_Apache - Fatal编程技术网

服务器根目录中的php include()?

服务器根目录中的php include()?,php,apache,Php,Apache,我正在从我的WAMP测试环境部署到在线测试 在本地,我的include路径如下所示: include('C/wamp/www...') 如何在服务器上找到等效路径 我尝试使用“/”访问根目录,但出现以下错误: 警告: require_once(/test123/mvc/views/txt/index_nav_txt.php) [函数.require once]:失败 开放流:没有这样的文件或目录 在里面 /home/user/public_html/test123/mvc/views/comp

我正在从我的WAMP测试环境部署到在线测试

在本地,我的include路径如下所示:

include('C/wamp/www...')
如何在服务器上找到等效路径

我尝试使用“
/
”访问根目录,但出现以下错误:

警告: require_once(/test123/mvc/views/txt/index_nav_txt.php) [函数.require once]:失败 开放流:没有这样的文件或目录 在里面 /home/user/public_html/test123/mvc/views/components/st_footer.php 在线37

致命错误:需要_once() [function.require]:打开失败 必修的 “/test123/mvc/views/txt/index_nav_txt.php” (include_path='。:/usr/lib/php:/usr/local/lib/php') 在里面 /home/user/public_html/test123/mvc/views/components/st_footer.php 在线37


实际上,您需要:

require_once("/home/codlife/public_html/test123/mvc/views/txt/index_nav_txt.php");
请注意
/home/codlife/public\u html/

首字母
/
将您带到服务器的根目录,您的代码位于
/home/codlife/public\u html/
中,您的意思是

$_SERVER['DOCUMENT_ROOT']

这基本上为您提供了工作网站目录的完整路径,即c:/wamp/www/(windows)或/var/www/vhost/domain.com/httpdocs/(linux)

您可能应该阅读include\u path()-这通常设置为包括文档根目录(您的网站所在位置)并且可以修改,这样就不必重复包含相同的路径

如何在服务器上找到等效路径

你找不到它-你告诉它应该在哪里。诚然,当您购买托管软件包时,这并不总是可行的(IME通常支持得很差,而且几乎没有文档)

首先要注意的是,无论代码位于何处/如何托管,您都应该始终使用相对于php包含路径上配置的目录的路径(或相对于浏览器请求最初调用的php脚本的路径-错误中引用的include_路径中的“.”条目)-而不是绝对路径。您可以通过以下方式轻松找到答案:

<?php
  print ini_get('include_path');
?>
(这将设置文档根目录的基本include_路径)


C.

使用配置文件存储以下内容:

$application_root = '/home/code_life/public_html/';
在此文件中,请使用所有特定于环境的变量或常量。当您在另一台计算机上部署应用程序时,只需更新配置文件

例如:

根应用程序中有一个名为settings with settings.php的文件夹,您可以在其中定义:

define('DIR_ROOT', dirname(dirname(__FILE__)) . '/');
现在,在每台机器上,DIR_ROOT将是应用程序的根,您无需更改任何内容

define('DIR_ROOT', dirname(dirname(__FILE__)) . '/');