zoukankan      html  css  js  c++  java
  • zip下载

    function download_img_all(){
    
       //图片数组
        $res = [
           [
             'img_path'=>'a.png',
           ],
           [
             'img_path'=>'b.png',
           ]
        ];
        //创建压缩包的路径
        $filename = $_SERVER['DOCUMENT_ROOT'].'/Dwonload.zip';
        $zip = new ipArchive;
        // $zip->deleteIndex();
        $zip->open($filename,$zip::CREATE);
        //往压缩包内添加目录
        $zip->addEmptyDir('images'); 
        foreach ($res as $value) {
             $fileData = file_get_contents($_SERVER['DOCUMENT_ROOT']."/".$value['img_path']);
            if ($fileData) {
                $add = $zip->addFromString('images/'.$value['img_path'], $fileData);
            }
        }
        $zip->close();
        //打开文件
       
        //下载文件
        ob_end_clean();
        header("Content-Type: application/force-download");
        header("Content-Transfer-Encoding: binary");
        header('Content-Type: application/zip');
        header('Content-Disposition: attachment; filename='.time().'.zip');
        header('Content-Length: '.filesize($filename));
        error_reporting(0);
        readfile($filename);
        flush();
        ob_flush();
    
    
    }
    
    echo download_img_all();
  • 相关阅读:
    笔记
    作用域及this指向案例总结
    笔记
    JS 事件(捕获和冒泡 兼容性写法)
    tab标签
    笔记
    JS入门(10.16)
    JS入门(10.15)
    关键渲染路径
    Practice1小学四则运算(改进)
  • 原文地址:https://www.cnblogs.com/liu-heng/p/7607494.html
Copyright © 2011-2022 走看看