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

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

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

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

    2. 压缩目录中的所有文件并下载生成的 .zip

      ZIP all files in directory and download generated .zip(压缩目录中的所有文件并下载生成的 .zip)
      <legend id='I6ojE'><style id='I6ojE'><dir id='I6ojE'><q id='I6ojE'></q></dir></style></legend><tfoot id='I6ojE'></tfoot>

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

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

                <bdo id='I6ojE'></bdo><ul id='I6ojE'></ul>
                本文介绍了压缩目录中的所有文件并下载生成的 .zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                嗯,首先,这是我的文件夹结构:

                Well, first of all, this is my folder structure:

                images/
                
                image1.png
                image11.png
                image111.png
                image223.png
                generate_zip.php
                

                这是我的 generate_zip.php:

                And this is mine generate_zip.php:

                <?php
                
                    $files = array($listfiles);
                
                    $zipname = 'adcs.zip';
                    $zip = new ZipArchive;
                    $zip->open($zipname, ZipArchive::CREATE);
                    foreach ($files as $file) {
                      $zip->addFile($file);
                    }
                    $zip->close();
                
                    header('Content-Type: application/zip');
                    header("Content-Disposition: attachment; filename='adcs.zip'");
                    header('Content-Length: ' . filesize($zipname));
                    header("Location: adcs.zip");
                
                    ?>
                

                如何从images/"文件夹中收集除generate_zip.php"之外的所有文件,并使其成为可下载的 .zip?在这种情况下,images/"文件夹总是有不同的图像.这可能吗?

                How to gather all the files from "images/" folder, except "generate_zip.php", and make it a downloadable .zip? In this case the "images/" folder always have a different image. Is that possible?

                推荐答案

                这将确保不会添加扩展名为 .php 的文件:

                this will ensure a file with .php extension will not be added:

                   foreach ($files as $file) {
                        if(!strstr($file,'.php')) $zip->addFile($file);
                    }
                

                这是重写的完整代码:

                <?php
                
                    $zipname = 'adcs.zip';
                    $zip = new ZipArchive;
                    $zip->open($zipname, ZipArchive::CREATE);
                    if ($handle = opendir('.')) {
                      while (false !== ($entry = readdir($handle))) {
                        if ($entry != "." && $entry != ".." && !strstr($entry,'.php')) {
                            $zip->addFile($entry);
                        }
                      }
                      closedir($handle);
                    }
                
                    $zip->close();
                
                    header('Content-Type: application/zip');
                    header("Content-Disposition: attachment; filename='adcs.zip'");
                    header('Content-Length: ' . filesize($zipname));
                    header("Location: adcs.zip");
                
                    ?>
                

                这篇关于压缩目录中的所有文件并下载生成的 .zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Proxy Authentication Required with cURL(cURL 需要代理身份验证)
                How to use a SOCKS 5 proxy with cURL?(如何使用带有 cURL 的 SOCKS 5 代理?)
                How to use HTTP_X_FORWARDED_FOR properly?(如何正确使用 HTTP_X_FORWARDED_FOR?)
                file_get_contents behind a proxy?(代理后面的 file_get_contents ?)
                pecl install cassandra throws: quot;error: Unable to load libcassandraquot;(pecl install cassandra 抛出:“错误:无法加载 libcassandra)
                Installing php datastax driver on ubuntu(在 ubuntu 上安装 php datastax 驱动)
                • <bdo id='J0dhS'></bdo><ul id='J0dhS'></ul>
                  <tfoot id='J0dhS'></tfoot>

                    <legend id='J0dhS'><style id='J0dhS'><dir id='J0dhS'><q id='J0dhS'></q></dir></style></legend>

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

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