PHP包括包括:(不同的目录)内 [英] PHP include inside an include (different directory)

查看:113
本文介绍了PHP包括包括:(不同的目录)内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前项目我工作的结构是这样的:

The structure for the current project I am working on is something like:


  • 根/ index.php文件

  • 根/包括/ PHP / first.php

  • 根/包括/ PHP / functions.php文件

所以index.php文件包括first.php:

So index.php includes first.php:

<?php include_once("includes/php/first.php"); ?>

通常然后我first.php会叫喜欢的功能:

Normally then my first.php would call functions like:

<?php include_once("includes/php/functions.php"); ?>

假设相对仍然会从索引页但是移动到新的服务器时,它不工作的时候。我试图从first.php使得相对路径:

Assuming the relative would still be from the index page however when moving to a new server it didn't work. I tried making the relative path from first.php:

include_once("functions.php");

和这似乎现在的工作。

这通常是正确的方式做到这一点?我想推出这个项目出这么只是任何人都将能够安装它。

Which would normally be the correct way to do this? I want to roll this project out so just about anyone would be able to install this.

推荐答案

包括相对于文件执行,包括。如果你真的想确保并避免任何歧义,你可以这样做:

includes are relative to the file doing the including. If you really want to make sure and avoid any ambiguity, you could do this:

include dirname(__FILE__) . "/functions.php";

这篇关于PHP包括包括:(不同的目录)内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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