piler/webui/model/message/restore.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2012-05-11 23:42:55 +02:00
<?php
class ModelMessageRestore extends Model {
public function download_files_as_zip($idlist = array()) {
$zip = new ZipArchive();
$randomid = generate_random_string(16);
2012-12-17 15:38:16 +01:00
$filename = DIR_BASE . "tmp/" . $randomid;
2012-05-11 23:42:55 +02:00
if($zip->open($filename, ZIPARCHIVE::CREATE) != true) { exit("cannot open <$filename>\n"); }
2013-04-09 15:02:10 +02:00
$this->model_search_message->connect_to_pilergetd();
2012-05-11 23:42:55 +02:00
foreach($idlist as $id) {
2012-09-06 15:27:20 +02:00
$piler_id = $this->model_search_message->get_piler_id_by_id($id);
$rawemail = $this->model_search_message->get_raw_message($piler_id);
2013-04-09 15:02:10 +02:00
2012-09-06 15:27:20 +02:00
$zip->addFromString($piler_id . ".eml", $rawemail);
2012-05-11 23:42:55 +02:00
AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $id, '');
}
2013-04-09 15:02:10 +02:00
$this->model_search_message->disconnect_from_pilergetd();
2012-05-11 23:42:55 +02:00
$zip->close();
header("Cache-Control: public, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/zip");
header("Expires: 0");
header("Content-Length: " . filesize($filename));
header("Content-Disposition: attachment; filename=archive-$randomid.zip");
header("Content-Transfer-Encoding: binary\n");
readfile($filename);
unlink($filename);
}
}
?>