PHP ZIP files on the fly

前端 未结 7 1744
有刺的猬
有刺的猬 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:41

    Your code is very close. You need to use the file name instead of the file contents.

    $zip->addFile(file_get_contents($filepath1), 'file1');
    

    should be

    $zip->addFile($filepath1, 'file1');
    

    http://us3.php.net/manual/en/function.ziparchive-addfile.php

    If you need to add files from a variable instead of a file you can use the addFromString function.

    $zip->addFromString( 'file1', $data );
    
    0 讨论(0)
提交回复
热议问题