PHP中的include()函数在XAMPP更新时表现不同 [英] include() function in PHP behaves differently on XAMPP update

查看:144
本文介绍了PHP中的include()函数在XAMPP更新时表现不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件结构是:

/ (Root)
|-- includes
|-- |-- global.php
|-- |-- config.php
|-- index.php

在我的 index.php 文件中,我写道:

In my index.php file I wrote :

<?php
include "includes/global.php";
?>

包括/ global.php I写道:

<?php
include "config.php";
?>

<$ c c中的 global.php $ c> index.php 将在 global.php config.php $ c>将不包括在内!

the global.php in index.php will be include whitout any problem but config.php in global.php will not be include !

我使用XAMPP并在我的旧版XAMPP(版本1.7.3)中我没有任何问题,但今天我安装了新版本的XAMPP(版本1.8.1)我有这个问题!

I use XAMPP and in my old version of XAMPP (version 1.7.3) I don't have any problem but today I installed new version of XAMPP (version 1.8.1) and I have this problem !

我应该使用绝对路径来包含 config.php 文件在 global.php 但是我不想使用绝对路径,我想像以前一样包含,我该怎么做?

I should use absolute path for including config.php file in global.php but I don't want to use absolute path, I want to include like before, how can I do this ?

推荐答案

include 中的路径始终相对于顶级脚本。因此,您的第二个(嵌套)包含将无法正确解析。

The path in include is always relative to the top-level script. So your second (nested) include will not resolve correctly.

一个常见的解决方法是使用:

A common workaround is to use:

<?php
include dirname(__FILE__)."/config.php";
?>

包含/ global.php 。无论顶层脚本位于何处,这都将使路径正确解析。

inside includes/global.php. This will make the path resolve correctly, no matter where the toplevel script is located.

这篇关于PHP中的include()函数在XAMPP更新时表现不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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