Improves zipped download.

This commit is contained in:
Lars Jung 2012-02-17 23:21:13 +01:00
parent f51a0b80a7
commit bc6e9fb150
5 changed files with 74 additions and 15 deletions

View file

@ -118,12 +118,26 @@ else if ($action === "zip") {
$hrefs = explode(":", trim($hrefs));
$zipFile = $zipit->zip($hrefs);
if ($zipFile === false) {
fail(2, "something went wrong while building the zip");
if ($zipFile) {
$response = array('status' => 'ok', 'id' => basename($zipFile), 'size' => filesize($zipFile));
} else {
$response = array('status' => 'failed', 'msg' => 'none');
}
echo json_encode($response);
}
else if ($action === "getzip") {
list($id) = checkKeys(array("id"));
fail(1, "zipped file not found: " . $id, !preg_match("/^h5ai-zip-/", $id));
$zipFile = str_replace("\\", "/", sys_get_temp_dir()) . "/" . $id;
fail(2, "zipped file not found: " . $id, !file_exists($zipFile));
header("Content-Disposition: attachment; filename=\"h5ai-selection.zip\"");
header("Content-Type: application/force-download");
// header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($zipFile));
header("Connection: close");
readfile($zipFile);