首页 > 解决方案 > 在 public_html 之外包含文件

问题描述

我想在 php 中包含 public_html 之外的文件。

我在 public_html 之外放置了一个文件,并尝试将此文件包含到 public_html/myDirectory 中存在的文件中。

我试过这个include '../../myFile.php';,但它不工作。

我哪里错了?

谢谢你的帮助。

标签: phpincludepublic-html

解决方案


/是获取目录名称的绝对系统路径

echo $_SERVER['DOCUMENT_ROOT'];

您的文件位置第一个文件夹/仅使用

include '/myfile.php';

第二个目录使用文件名

 include '/filename/myfile.php';

其他明智的使用 curl 或文件获取

file_get_contents("/myfile.php"); //http://yoururl.com/myfile.php

更新您的主要代码包括备用


推荐阅读