22
2023
12

php压缩一个文件夹 ,php下载多个图片

        $zip = new \ZipArchive ();
 
        $zipname = "/var/www/imgzip.zip";
 
        if ($zip->open($zipname, \ZIPARCHIVE::CREATE)!==TRUE) {
            echo '无法打开文件,或者文件创建失败';die;
        }
 
        $fileArr = explode(',',$data['record_con']);//多张图片的地址
        foreach ( $fileArr as $file ) {
            $url = $this->qnDownload($file);
            //这里将服务器上的文件添加到下载内容中,并重新赋值下载zip文件内该文件的路径
            $fileContent = file_get_contents($url);
            //添加图片。参数1 文件名字  参数二 二进制流
            $zip->addFromString(basename($file), $fileContent);
//            $zip->addFile (  $url,basename($url));
        }
 
        $zip->close ();
        header ( "Content-Type: application/zip" );
        header ( "Content-Transfer-Encoding: Binary" );
        header ( "Content-Length: " . filesize ( $zipname ) );
        header ( "Content-Disposition: attachment; filename=\"" . basename ( $zipname ) . "\"" );
 
        readfile ( $zipname );
         @unlink ( $zipname );


« 上一篇 下一篇 »

评论列表:

1.www.501h.com  2024-11-15 22:42:19 回复该评论
《水稻克星》泰国剧高清在线免费观看:https://www.jgz518.com/xingkong/143239.html

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。