tiki-download_forum_attachment.php 1.51 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
6
// 
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9
// $Id$
10

11 12
$force_no_compression = true;
require_once ('tiki-setup.php');
13

14 15 16 17
// roysinn: shouldn't need attach permission for download . . .
//if ($tiki_p_forum_attach != 'y') {
//	die;
//}
18 19 20

if (!isset($_REQUEST["attId"])) {
	die;
21
}
22

23
$commentslib = TikiLib::lib('comments');
24 25
$info = $commentslib->get_thread_attachment($_REQUEST["attId"]);

26
if ( empty($info['filetype']) || $info['filetype'] == 'application/x-octetstream' || $info['filetype'] == 'application/octet-stream' ) {
27 28
	$mimelib = TikiLib::lib('mime');
	$info['filetype'] = $mimelib->from_filename($info['filename']);
29
}
30 31 32
$type = &$info["filetype"];
$file = &$info["filename"];
$content = &$info["data"];
33

34
session_write_close();
35 36
header("Content-type: $type");
header("Content-Disposition: inline; filename=\"$file\"");
37

mose's avatar
mose committed
38
// Added Damian March04 request of Akira123
39 40 41
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: Public");
mose's avatar
mose committed
42

43 44 45 46 47
// if database has content, means file was uploaded to DB storage
if (strlen($content) > 0) {
	echo "$content";
} else if (file_exists($info["dir"] . $info["path"])) {
    // Check if file was uploaded to file syste
48
	readfile($info["dir"] . $info["path"]);
49
} else {
50 51
	// Something is wrong
	die('File data was not found');
52
}