【问题标题】:how to access documents(.pdf .doc etc) which are stored outside of the root folder [duplicate]如何访问存储在根文件夹之外的文档(.pdf .doc 等)[重复]
【发布时间】:2012-10-08 10:09:58
【问题描述】:

可能重复:
How to serve documents from outside the web root using PHP?

基本上这是我的第一个站点之一,但是我的客户想要存储的一些文档包含敏感信息,所以我已经阅读了,似乎解决这个问题的最佳方法是将文档存储在根文件夹之外.

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

【问题讨论】:

    标签: php root documents


    【解决方案1】:

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

    【讨论】:

    • 谢谢,这正是我想要的!也感谢您的明确指示。
    猜你喜欢
    • 2016-10-17
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    相关资源
    最近更新 更多