0

我正在使用该方法生成示例 zip 文件。

不幸的是,zip 文件的输出没有解压缩到预期的输入。

public function generateZip(Request $req) { 
    $response = new StreamedResponse(function()
    {
        $opt = array(

            'comment' => 'test zip file.',
            'send_headers'=>true,
        );

        $zip = new ZipStream\ZipStream('example.zip');

        # create a file named 'hello.txt' 
        $zip->addFile('hello.txt', 'This is the contents of hello.txt');


        # finish the zip stream
        $zip->finish();
     });


    return $response;

生成的文件example.zip,解压缩文件后解压缩“hello.txt”,但它的内容是一个空白的新行

…»,V¢íåTÖ‰¸ºí‘ºíbÖ¸4Öå‘úú|Ωíä

我的努力基于以下代码:

在 Symfony 中使用 ZipStream:流式 zip 下载不会在 Mac OSX 上使用 Archive Utility 解压缩

我的调试步骤是这样开始的:

1) 尝试使用 Amazon S3 流生成 zip

2)修改设置,删除压缩

3) 将问题隔离为最简单的结果

4) 添加输出缓冲和输出刷新以尝试拦截任何输出。

我的路线是这样的:

Route::get("/generate-zip", 'myController@generateZip');

4

1 回答 1

0

不幸的是,我的问题与图书馆无关。我(我认为)不小心在 /vendor 中保存了一个文件,其中包含一些额外的代码。擦拭供应商文件夹并重新安装就可以了。

于 2017-08-29T18:42:51.657 回答