php-创建大型zip文件块服务器
我使用下面的代码创建和下载大型zip文件。文件夹包含大量文件,大约20000到30000个文件。总文件大小平均为2GB。这段代码适用于小文件,但如果超过10000个文件,服务器会在几分钟内无响应php-创建大型zip文件块服务器,php,file,download,zip,large-files,Php,File,Download,Zip,Large Files,我使用下面的代码创建和下载大型zip文件。文件夹包含大量文件,大约20000到30000个文件。总文件大小平均为2GB。这段代码适用于小文件,但如果超过10000个文件,服务器会在几分钟内无响应 <?php $folder= "../path/"; header('Pragma: no-cache'); header('Content-Description: File Download'); header('Content-disposition: attachme
<?php
$folder= "../path/";
header('Pragma: no-cache');
header('Content-Description: File Download');
header('Content-disposition: attachment; filename="myZip.zip"');
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
chdir( $folder );
$fp = popen('zip -r -0 - ' . $folder, 'r');
while(!feof($fp)) {
echo fread($fp, 8192);
}
//Closing the stream
pclose($fp);
?>
在下载真正开始之前,您需要准备压缩此文件。最好是在不同的服务器上,而不是在提供HTTP请求的服务器上。我已经尝试过这种方法,但不起作用。为了澄清,您已经尝试过直接从完整的zip文件流式传输,而不是输出zip
?如果是这样的话,你能改变你的问题例子来反映你的尝试吗?因为现在这个例子不是一个好的起点。