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

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

                相关文档推荐

                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 的问题)
                • <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>