如何访问存储在根文件夹之外的文档(.pdf .doc等)



可能的重复项:
如何使用 PHP 从 Web 根目录外部提供文档?

基本上这是我的第一个站点之一,但是我的客户想要存储的某些文档包含敏感信息,因此我已经阅读了,似乎最好的方法是将文档存储在根文件夹之外。

但是,如果它们存储在根文件夹的oustide中,我将如何让客户端访问它们进行下载?

当你告诉浏览器下载它时,只需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必须有权访问它。

最新更新