PHP ZIP files on the fly

前端 未结 7 1775
有刺的猬
有刺的猬 2020-12-02 17:06

What\'s the easiest way to zip, say 2 files, from a folder on the server and force download? Without saving the \"zip\" to the server.

    $zip = new ZipArc         


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-02 17:33

    maraspin's Answer is what I tried. Strangely, I got it working by removing the header line that references the file size:

    header('Content-Length: ' . filesize($file));
    

    With the above change, the code works like a breeze! Without this change, I used to get the following error message:

    End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive.

    Test environment:

    OS: Ubuntu 10.10 Browser: Firefox And the default LAMP stack.

提交回复
热议问题