zoukankan      html  css  js  c++  java
  • php 3.2 生成压缩文件,并下载

        public function zip_download()
        {
    
            $array = array(
                'http://local.qki.com/site_upload/erweima/20190826/1566809174292_100063_865373044010119.png',
                'http://local.qki.com/site_upload/erweima/20190826/1566809222969_100064_865373044013253.png'
            );
    
            $tmpFile = tempnam('/temp', '');        //临时文件
            $zip = new ipArchive();                           //php内置的压缩类
            $zip->open($tmpFile, ipArchive::CREATE);
    
            foreach ($array as $value) {
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_POST, 0);
                curl_setopt($ch, CURLOPT_URL, $value);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                $fileContent = curl_exec($ch);
                curl_close($ch);
                $zip->addFromString(basename($value), $fileContent);  //将文件循环压缩到压缩包
            }
    
            $filename = date('YmdHis',time()) . '_file.zip';
            $zip->close();
            header('Content-Type: application/zip');
            header('Content-disposition: attachment; filename=' . $filename);
            header('Content-Length: ' . filesize($tmpFile));  
            readfile($tmpFile);
            unlink($tmpFile);
        }
  • 相关阅读:
    python
    js 对嵌套页面的父页面进行跳转
    HTML 添加空格
    python
    python
    python
    面向对象编程基础(进阶4)
    Python模块(进阶3)
    Python函数式编程(进阶2)
    python进阶介绍(进阶1)
  • 原文地址:https://www.cnblogs.com/pansidong/p/11420014.html
Copyright © 2011-2022 走看看