php嵌套包含行为 [英] php nested include behavior

查看:83
本文介绍了php嵌套包含行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码的许多地方,我做的事情如下:

In many places in my code, I do things like:

file1.php:
<?php
include('../file2.php');

file2.php:
<?php
include('anotherdirectory/file3.php');

根据我尝试使用的服务器或设置,它可以设置包含器的相对路径或来自包括。这真令人困惑。
所以file1可能会尝试包含../anotherdirectory/file3.php,或者它可能会尝试anotherdirectory / file3.php。

Depending on the server or settings I try this on, it either sets the relative paths from the "includer" or from the "includee". This is really confusing. So file1 might try to include "../anotherdirectory/file3.php" or it might try "anotherdirectory/file3.php".

什么设置要求这个行为?我希望控制这个......

What settings dictate this behavior? I want to have control over this...

推荐答案

如果我需要使用相对路径,我使用以下语法:

In cases when I need to use relative paths I use the following syntax:

include (realpath(dirname(__FILE__)."/another_folder/myfile.php"));

这篇关于php嵌套包含行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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