我正在使用该方法生成示例 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');