mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 00:41:59 +01:00
download attachments in 1 zip file
This commit is contained in:
parent
2a0707e55b
commit
dc8036f220
45
webui/controller/message/attachments.php
Normal file
45
webui/controller/message/attachments.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ControllerMessageAttachments extends Controller {
|
||||
|
||||
public function index(){
|
||||
|
||||
$this->id = "content";
|
||||
$this->template = "message/headers.tpl";
|
||||
$this->layout = "common/layout-empty";
|
||||
|
||||
$request = Registry::get('request');
|
||||
$db = Registry::get('db');
|
||||
|
||||
$this->load->model('search/search');
|
||||
$this->load->model('search/message');
|
||||
$this->load->model('message/zip');
|
||||
|
||||
$this->document->title = $this->data['text_message'];
|
||||
|
||||
$this->data['id'] = @$this->request->get['id'];
|
||||
|
||||
if(!verify_piler_id($this->data['id'])) {
|
||||
AUDIT(ACTION_UNKNOWN, '', '', $this->data['id'], 'unknown id: ' . $this->data['id']);
|
||||
die("invalid id: " . $this->data['id']);
|
||||
}
|
||||
|
||||
if(!$this->model_search_search->check_your_permission_by_id($this->data['id'])) {
|
||||
AUDIT(ACTION_UNAUTHORIZED_VIEW_MESSAGE, '', '', $this->data['id'], '');
|
||||
die("no permission for " . $this->data['id']);
|
||||
}
|
||||
|
||||
$this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']);
|
||||
|
||||
//AUDIT(ACTION_DOWNLOAD_ATTACHMENT, '', '', $messageid, $this->data['id']);
|
||||
|
||||
$this->model_message_zip->download_attachments_as_zip($this->data['piler_id']);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
55
webui/model/message/zip.php
Normal file
55
webui/model/message/zip.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
class ModelMessageZIP extends Model {
|
||||
|
||||
|
||||
public function download_attachments_as_zip($piler_id = '') {
|
||||
|
||||
$zip = new ZipArchive();
|
||||
$pid = array();
|
||||
|
||||
$randomid = generate_random_string(16);
|
||||
|
||||
$filename = DIR_BASE . "tmp/" . $randomid;
|
||||
|
||||
if($zip->open($filename, ZIPARCHIVE::CREATE) != true) { exit("cannot open <$filename>\n"); }
|
||||
|
||||
$attachments = $this->model_search_message->get_attachment_list($piler_id);
|
||||
|
||||
foreach($attachments as $a) {
|
||||
$attachment = $this->model_search_message->get_attachment_by_id($a['id']);
|
||||
$fp = fopen(DIR_BASE . 'tmp/' . $a['id'], "w+");
|
||||
if($fp) {
|
||||
fwrite($fp, $attachment['attachment']);
|
||||
fclose($fp);
|
||||
|
||||
$zip->addFile(DIR_BASE . 'tmp/' . $a['id'], $attachment['filename']);
|
||||
}
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
|
||||
foreach($attachments as $a) {
|
||||
unlink(DIR_BASE . 'tmp/' . $a['id']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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=" . $piler_id . ".zip");
|
||||
header("Content-Transfer-Encoding: binary\n");
|
||||
|
||||
readfile($filename);
|
||||
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -48,7 +48,7 @@
|
||||
<strong><?php print $message['date']; ?></strong><br />
|
||||
<?php foreach($attachments as $a) { ?>
|
||||
<span><i class="attachment icon-paper-clip icon-large" title="Message Attachment"></i> <a href="index.php?route=message/attachment&id=<?php print $a['id']; ?>"><?php print $a['name']; ?></a></span>
|
||||
<?php } ?><br/>
|
||||
<?php } ?><?php if(count($attachments) > 1) { ?>| <a href="index.php?route=message/attachments&id=<?php print $id; ?>"><i class="icon-briefcase"></i></a><?php } ?><br/>
|
||||
</div>
|
||||
<div class="messagecontents">
|
||||
<?php print $message['message']; ?>
|
||||
|
@ -48,7 +48,7 @@
|
||||
<strong><?php print $message['date']; ?></strong><br />
|
||||
<?php foreach($attachments as $a) { ?>
|
||||
<span><img src="<?php print ICON_ATTACHMENT; ?>" /><a href="index.php?route=message/attachment&id=<?php print $a['id']; ?>"><?php print $a['name']; ?></a></span>
|
||||
<?php } ?><br/>
|
||||
<?php } ?><?php if(count($attachments) > 1) { ?>| <a href="index.php?route=message/attachments&id=<?php print $id; ?>"><i class="icon-briefcase"></i></a><?php } ?><br/>
|
||||
</div>
|
||||
|
||||
<div class="messagecontents">
|
||||
|
Loading…
Reference in New Issue
Block a user