zip and download files using php

前端 未结 7 875
暗喜
暗喜 2021-02-02 03:41

I am trying to zip and download files from a folder named \"upload\". Zip file is downloading but I couldn\'t open (extract) it. I am getting an error like \"The archive is eith

7条回答
  •  无人及你
    2021-02-02 04:09

     $zip = new ZipArchive;
            if ($zip->open('assets/myzip.zip',  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!';
           }
    

    I got this code to download files from a folder.

提交回复
热议问题