如何访问存储在根文件夹之外的文档(.pdf .doc等) [英] how to access documents(.pdf .doc etc) which are stored outside of the root folder

查看:56
本文介绍了如何访问存储在根文件夹之外的文档(.pdf .doc等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何使用PHP?

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

Basically this is one of my first sites, however some of the documents my client wants to store contain sensitive information, so i have read up and it seems the best way to approach this is to store the documents outside of the root folder.

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

However if they are stored oustide of the root folder how would I go about letting the client access them for download?

推荐答案

当您告诉浏览器下载它时,只需 readfile()

Simply readfile() when you tell browser to download it

$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必须有权访问它.

Remember that Apache must have access to it.

这篇关于如何访问存储在根文件夹之外的文档(.pdf .doc等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆