包括父目录中的php文件

  • 本文关键字:php 文件 包括父 php
  • 更新时间 :
  • 英文 :


我在"/user/files/new"文件夹中有一个user_ip_location.php文件。

文件的完整url是

/user/files/new/user_ip_location.php

我想将此文件包含在位于根目录中的profile.php文件中

我已经尝试了以下代码

 include("/././user_ip_location");

 include("http://example.com/user/files/new/user_ip_location");

两者都不工作,第一个是返回没有这样的文件或目录,第二个是没有加载页面,浏览器返回错误无法定位到远程服务器

有什么办法解决它吗?

您需要用双点.. 指示上一个目录

include("../../user_ip_location.php");

如果我正确理解您的问题,那么您在some目录中,并且希望包含来自/user/files/new/user_ip_location.php的文件。因此,只要通过指定路径来包含它就可以了。

在您的示例中,这将是:include("/user/files/new/user_ip_location.php");

如果要包含的文件级别高于当前目录,只需使用..(如include("../../user_ip_location.php"); )来指定即可

试试这个:

include './files/new/user_ip_location.php';

最新更新