This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathattachment.php
60 lines (46 loc) · 1.52 KB
/
attachment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
require_once(dirname(__FILE__)."/config.inc.php");
require_once(dirname(__FILE__)."/classes/session.class.php");
$session = new Session($config);
$boardid = $_REQUEST["boardid"];
$messageid = $config->decodeMessageID($_REQUEST["messageid"]);
$partid = $_REQUEST["partid"];
try {
$board = $config->getBoard($boardid);
if (!$board->mayRead($session->getAuth())) {
throw new Exception("Keine Berechtigung!");
exit;
}
$connection = $board->getConnection();
if ($connection === null) {
throw new Exception("Board enthaelt keine Group!");
}
$connection->open($session->getAuth());
$group = $connection->getGroup();
$connection->close();
$message = $group->getMessage($messageid);
if ($message === false) {
$attachment = $session->getAttachment($partid);
} else {
$attachment = $message->getAttachment($partid);
}
if ($attachment === null) {
throw new Exception("Attachment ungueltig!");
}
$disposition = $attachment->getDisposition();
$filename = $attachment->getFilename();
// Fix for images
if (preg_match("$^image/$", $attachment->getMimeType())) {
$disposition = "inline";
}
// see RFC 2616 for these Headers
header("Content-Type: ".$attachment->getMimeType());
header("Content-Length: ".$attachment->getLength());
if (!empty($disposition)) {
header("Content-Disposition: " . $disposition . ( (empty($filename) or $disposition == "inline") ? "" : "; filename=\"".addslashes($filename)."\"" ) );
}
print($attachment->getContent());
} catch (Exception $e) {
$template->viewexception($e);
}
?>