0

いくつかの画像を圧縮してユーザーに動的に表示する古いスクリプトを編集しています。

ほとんどすべてのコードを書き直しましたが、zipファイルの内容を出力する方法が見つかりません。サーバーに書き込むことは非常に望ましくありません。

次のコマンドでファイルを作成します。

$z = new ZipArchive();

次のコンテンツを追加できます:

$z->addFromString("filename",$string);

そして、私はそれを動的に提示したいと思います:

header("Content-Type: application/zip;");
header("Content-Disposition: attachment; filename=file.zip;");

// I need a function to read the contents of the zipfile here. Something like:
echo $z->filecontent();

これに使用する関数がわかりません。

4

2 に答える 2

0

If you read the documentation, look at the close() method to actually save the file physically to the filesystem. Then you can use readfile() on the saved file

于 2013-02-18T22:09:17.537 に答える
0

ファイルを開き、おそらく一時名で作成します。このようなもの:

$name = tempnam('/tmp','zip');
$z->open($name, ZIPARCHIVE::CREATE)

すべてのファイルを追加したら、それを閉じます。

$z->close();

データを送信する準備ができたら、次のようにします。

readfile($name);

完了したら、一時ファイルを次のようにクリーンアップします。

unlink($name);
于 2013-02-18T22:09:50.150 に答える