【发布时间】:2012-10-08 10:09:58
【问题描述】:
可能重复:
How to serve documents from outside the web root using PHP?
基本上这是我的第一个站点之一,但是我的客户想要存储的一些文档包含敏感信息,所以我已经阅读了,似乎解决这个问题的最佳方法是将文档存储在根文件夹之外.
但是,如果它们存储在根文件夹之外,我将如何让客户端访问它们进行下载?
【问题讨论】:
可能重复:
How to serve documents from outside the web root using PHP?
基本上这是我的第一个站点之一,但是我的客户想要存储的一些文档包含敏感信息,所以我已经阅读了,似乎解决这个问题的最佳方法是将文档存储在根文件夹之外.
但是,如果它们存储在根文件夹之外,我将如何让客户端访问它们进行下载?
【问题讨论】:
当你告诉浏览器下载它时只需readfile()
$file = '/outsite/website/file.doc';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=" . basename($file));
header("Content-Type: " . mime_content_type($file));
header("Content-Length: " . filesize($file));
header("Content-Transfer-Encoding: binary");
readfile($file);
exit;
记住 Apache 必须有权访问它。
【讨论】: