PHP获取文档根目录之外的文件

标签 php apache ubuntu directory document-root

这是我的项目结构:

Web 根目录/文档根目录:

/var/www/ all the website files in the the 'www' folder

我想使用 requireinclude我的文件夹中的一个文件在网络根目录/文档根目录之外:
/var/extra-files

如何在 extra-files 中获取文件使用 require 的文件夹或 include ?
require "OUTSIDE DOCUMENT ROOT/extra-files

谢谢

最佳答案

首先确保apache作为读取 /var/extra-files 上文件的权限,那么您可以使用:

require "/var/extra-files/file.php";

您可能想阅读 Difference between require, include and require_once?

关于PHP获取文档根目录之外的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43713980/

相关文章:

c - 如何在c中链接pnglite库?

php - 从对象调用函数?

php - 无法使用ubuntu在GCE实例中通过php连接到mysql数据库

php - 如何在 PHP 中向 DateTime() 对象添加一分钟?

php - OSX Mavericks - 使用子域设置 Apache

php - 为什么 file_put_contents 从浏览器运行时有权限问题?

java jbutton文本不适合不同的环境

ubuntu - libcudart.so 的路径是什么?

php - 今天、昨天、每月日志的 MySQL 表设置

php - 确定论坛帖子所在的页面