<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 文件并下载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                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>