2017-08-29 94 views
0

我正在使用該方法生成示例zip文件。Laravel 5.4中的Zipstream - 數據已損壞

不幸的是,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Öå‘úú|Ωíä 

我的努力已經關閉基於這個代碼:

Using ZipStream in Symfony: streamed zip download will not decompress using Archive Utility on Mac OSX

我的調試步驟啓動此:

1)試圖產生壓縮此使用Amazon S3流

2)與設置修改一下,除去壓縮

3)分離的問題,以最簡單的結果

4)添加輸出緩衝&輸出平齊試圖攔截任何輸出。

我的路線是這樣的:

Route::get("/generate-zip", '[email protected]');

回答

0

不幸的是我的問題是無關的庫。我曾經(我認爲)不小心將一個文件保存在供應商內部,其中有一些額外的代碼。擦拭供應商文件夾並重新安裝的訣竅。