Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php-创建大型zip文件块服务器_Php_File_Download_Zip_Large Files - Fatal编程技术网

php-创建大型zip文件块服务器

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

我使用下面的代码创建和下载大型zip文件。文件夹包含大量文件,大约20000到30000个文件。总文件大小平均为2GB。这段代码适用于小文件,但如果超过10000个文件,服务器会在几分钟内无响应

<?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
?如果是这样的话,你能改变你的问题例子来反映你的尝试吗?因为现在这个例子不是一个好的起点。