<i id='YjmUu'><tr id='YjmUu'><dt id='YjmUu'><q id='YjmUu'><span id='YjmUu'><b id='YjmUu'><form id='YjmUu'><ins id='YjmUu'></ins><ul id='YjmUu'></ul><sub id='YjmUu'></sub></form><legend id='YjmUu'></legend><bdo id='YjmUu'><pre id='YjmUu'><center id='YjmUu'></center></pre></bdo></b><th id='YjmUu'></th></span></q></dt></tr></i><div id='YjmUu'><tfoot id='YjmUu'></tfoot><dl id='YjmUu'><fieldset id='YjmUu'></fieldset></dl></div>

      <small id='YjmUu'></small><noframes id='YjmUu'>

      1. <tfoot id='YjmUu'></tfoot>

        • <bdo id='YjmUu'></bdo><ul id='YjmUu'></ul>
        <legend id='YjmUu'><style id='YjmUu'><dir id='YjmUu'><q id='YjmUu'></q></dir></style></legend>
      2. 创建一个 zip 文件并下载它

        Create a zip file and download it(创建一个 zip 文件并下载它)

        <small id='noxE0'></small><noframes id='noxE0'>

          <tbody id='noxE0'></tbody>
          <bdo id='noxE0'></bdo><ul id='noxE0'></ul>
          • <tfoot id='noxE0'></tfoot>
            <legend id='noxE0'><style id='noxE0'><dir id='noxE0'><q id='noxE0'></q></dir></style></legend>
            1. <i id='noxE0'><tr id='noxE0'><dt id='noxE0'><q id='noxE0'><span id='noxE0'><b id='noxE0'><form id='noxE0'><ins id='noxE0'></ins><ul id='noxE0'></ul><sub id='noxE0'></sub></form><legend id='noxE0'></legend><bdo id='noxE0'><pre id='noxE0'><center id='noxE0'></center></pre></bdo></b><th id='noxE0'></th></span></q></dt></tr></i><div id='noxE0'><tfoot id='noxE0'></tfoot><dl id='noxE0'><fieldset id='noxE0'></fieldset></dl></div>

                1. 本文介绍了创建一个 zip 文件并下载它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图通过在本地服务器上创建 zip 文件来下载 2 个文件.该文件以 zip 格式下载,但是当我尝试解压缩它时.它给出了错误:未找到中央目录结尾签名.要么这个文件不是一个 zip 文件,或者它构成一个多部分存档的磁盘.在里面后一种情况,将在以下位置找到中央目录和 zip 文件注释此存档的最后一个磁盘.

                  I am trying to download a 2 files by creating the zip file on local-server.the file is downloaded in zip format but when i try to extract it.it gives error: End-of-central-directory signature not found. Either this file is not a zip file, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zip file comment will be found on the last disk(s) of this archive.

                  我为此使用的以下代码:

                  the following code i am using for this:

                   <?php
                  $file_names = array('iMUST Operating Manual V1.3a.pdf','iMUST Product Information Sheet.pdf');
                  
                  //Archive name
                  $archive_file_name=$name.'iMUST_Products.zip';
                  
                  //Download Files path
                  $file_path=$_SERVER['DOCUMENT_ROOT'].'/Harshal/files/';
                  
                  
                  zipFilesAndDownload($file_names,$archive_file_name,$file_path);
                  
                  function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
                  {
                          //echo $file_path;die;
                      $zip = new ZipArchive();
                      //create the file and throw the error if unsuccessful
                      if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
                          exit("cannot open <$archive_file_name>
                  ");
                      }
                      //add each files of $file_name array to archive
                      foreach($file_names as $files)
                      {
                          $zip->addFile($file_path.$files,$files);
                          //echo $file_path.$files,$files."
                  
                      }
                      $zip->close();
                      //then send the headers to force download the zip file
                      header("Content-type: application/zip"); 
                      header("Content-Disposition: attachment; filename=$archive_file_name"); 
                      header("Pragma: no-cache"); 
                      header("Expires: 0"); 
                      readfile("$archive_file_name");
                      exit;
                  }
                  
                  
                  
                  
                  ?>
                  

                  我检查了传递给函数的所有变量的值,一切都很好.所以请看这个.提前致谢.

                  i checked the values of all variables which are passing into the function,all are fine.so please look this.Thanks in advance.

                  推荐答案

                  添加 Content-length 标头,以字节为单位描述 zip 文件的大小.

                  Add Content-length header describing size of zip file in bytes.

                  header("Content-type: application/zip"); 
                  header("Content-Disposition: attachment; filename=$archive_file_name");
                  header("Content-length: " . filesize($archive_file_name));
                  header("Pragma: no-cache"); 
                  header("Expires: 0"); 
                  readfile("$archive_file_name");
                  

                  还要确保 之前和 ?> 之后绝对没有空格.我在这里看到一个空格:

                  Also make sure that there is absolutely no white space before <? and after ?>. I see a space here:

                   <?php
                  $file_names = array('iMUST Operating Manual V1.3a.pdf','iMUST Product Information Sheet.pdf');
                  

                  这篇关于创建一个 zip 文件并下载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                2. <small id='rYOLX'></small><noframes id='rYOLX'>

                  <tfoot id='rYOLX'></tfoot>

                    <tbody id='rYOLX'></tbody>

                  1. <i id='rYOLX'><tr id='rYOLX'><dt id='rYOLX'><q id='rYOLX'><span id='rYOLX'><b id='rYOLX'><form id='rYOLX'><ins id='rYOLX'></ins><ul id='rYOLX'></ul><sub id='rYOLX'></sub></form><legend id='rYOLX'></legend><bdo id='rYOLX'><pre id='rYOLX'><center id='rYOLX'></center></pre></bdo></b><th id='rYOLX'></th></span></q></dt></tr></i><div id='rYOLX'><tfoot id='rYOLX'></tfoot><dl id='rYOLX'><fieldset id='rYOLX'></fieldset></dl></div>

                        • <legend id='rYOLX'><style id='rYOLX'><dir id='rYOLX'><q id='rYOLX'></q></dir></style></legend>
                          • <bdo id='rYOLX'></bdo><ul id='rYOLX'></ul>