您可以使用PHP的ZipArchive
類來製作ZIP,然後將其流式傳輸到瀏覽器。
<?php
// Create temp zip file
$zip = new ZipArchive;
$temp = tempnam(sys_get_temp_dir(), 'zip');
$zip->open($temp);
// Add files
$zip->addFromString('file.jpg', file_get_contents('http://path/to/file.jpg'));
$zip->addFile('/this/is/my/file.txt');
// Write temp file
$zip->close();
// Stream file to browser
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=myFile.zip');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($temp));
readfile($temp);
unlink($temp);
exit;
你的問題是? – 2012-07-16 18:47:58
它的哪個部分是你的?你可以使用PHP嗎? http://davidwalsh.name/create-zip-php – ametren 2012-07-16 18:48:57
我試着在 – 2012-07-16 19:22:39