Create a zip file and download it

后端 未结 7 752
滥情空心
滥情空心 2020-11-29 04:16

I am trying to download a 2 files by creating the zip file on local-server.the file is downloaded in zip format but when i try to extract it.it gives error: End-of-

7条回答
  •  北海茫月
    2020-11-29 05:00

    $zip = new ZipArchive;
    $tmp_file = 'assets/myzip.zip';
        if ($zip->open($tmp_file,  ZipArchive::CREATE)) {
            $zip->addFile('folder/bootstrap.js', 'bootstrap.js');
            $zip->addFile('folder/bootstrap.min.js', 'bootstrap.min.js');
            $zip->close();
            echo 'Archive created!';
            header('Content-disposition: attachment; filename=files.zip');
            header('Content-type: application/zip');
            readfile($tmp_file);
       } else {
           echo 'Failed!';
       }
    

提交回复
热议问题