PHP:如何访问根目录以外的下载文件夹? [英] PHP: How to access download folder outside root directory?
问题描述
我如何去创建一个PHP脚本/网页,将允许会员/买家下载存储在位于根目录之外的下载文件夹压缩文件(产品)?我使用的Apache服务器。请帮忙!
How do I go about creating a PHP script/page that will allow members/buyers to download zipped files(products) stored in a download folder located outside root directory? I'm using Apache server. Please help!
谢谢!
保罗-G。
Thanks! Paul G.
推荐答案
我相信你想完成(流通过PHP现有的zip文件)可以做类似这里的答案是什么:
<一href=\"http://stackoverflow.com/questions/4357073/on-the-fly-zipping-streaming-of-large-files-in-php-or-otherwise/4357904#4357904\">On-the-fly压缩和解和放大器;大文件,PHP中的流媒体或其他方式
I believe what you're trying to accomplish (stream an existing zip file via php) can be done similar to the answer here: On-the-fly zipping & streaming of large files, in PHP or otherwise
从这个答案code稍微修改后的版本:
Slightly modified version of code from this answer:
// make sure to send all headers first
// Content-Type is the most important one (probably)
//
header('Content-Type: application/x-gzip');
$filename = "/path/to/zip.zip";
$fp = fopen($filename, "rb");
// pick a bufsize that makes you happy
$bufsize = 8192;
$buff = '';
while( !feof($fp) ) {
$buff = fread($fp, $bufsize);
echo $buff;
}
pclose($fp);
这篇关于PHP:如何访问根目录以外的下载文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!