本文介绍了PHP:如何访问根目录下的下载文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建一个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!
谢谢!
Paul G。
Thanks!Paul G.
推荐答案
我相信你想要完成什么(通过php流式传输现有的zip文件)可以类似于这里的答案:
I believe what you're trying to accomplish (stream an existing zip file via php) can be done similar to the answer here:LAMP: How to create .Zip of large files for the user on the fly, without disk/CPU thrashing
该答案稍微修改后的版本代码:
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:如何访问根目录下的下载文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!