-2

フォルダーを圧縮してそのzipファイルをlaravel4にダウンロードする方法を教えてください。

フォルダを圧縮する必要があります/public/zipfolder/

圧縮後、自動ダウンロードzipfolder.zip

このパッケージをインストールします

https://github.com/codeless/ziparchiveex

へのルート

public function show($id)
{
    //echo $id;
    # ZipArchive as usual:
    $zip = new ZipArchiveEx();
    //$zip->open('my.zip', ZIPARCHIVE::OVERWRITE);

    # Add whole directory including contents:
    $zip->addDir('/public/zipfolder/');

    # Only add the contents of the directory, but
    # not the directory-entry of "mydir" itself:
    //$zip->addDirContents('mydir');

    # Close archive (as usual):
    $zip->close();
}

そして、私は以下のエラーが発生しました

ZipArchive::addEmptyDir(): 無効またはユニット化されたZipオブジェクト

4

2 に答える 2

0

これは、圧縮後に my.zip を自動ダウンロードした後に適用されるコードです。

public function show($id)
{
    //echo $id;
    # ZipArchive as usual:
    $zip = new ZipArchiveEx();
    $zip->open('my.zip', ZIPARCHIVE::OVERWRITE);

    # Add whole directory including contents:
    $zip->addDir('/public/zipfolder/');

    # Only add the contents of the directory, but
    # not the directory-entry of "mydir" itself:
    //$zip->addDirContents('mydir');

    # Close archive (as usual):
    $zip->close();

    // Stream the file to the client 
    header("Content-Type: application/zip"); 
    header("Content-Length: " . filesize('my.zip')); 
    header("Content-Disposition: attachment; filename=\"my.zip\""); 
    readfile('my.zip'); 

    unlink('my.zip');
}
于 2014-11-21T16:19:42.133 に答える