• <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

      时间:2023-07-15
      <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:getcwd() 和 dirname(__FILE__) 之间的区别?我应该使用哪个? 下一篇:PHP 需要顶级目录中的文件

                相关文章

                • <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>