summaryrefslogtreecommitdiff
path: root/forum/utils/file.php
blob: 50993b5cd2da308271800c6362c0fed0dc897295 (plain)
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
<?php
 
include_once("config.php");
include_once($UTIL_DIR . "/mimetypes.php");
include_once($UTIL_DIR . "/files.php");

function getFile($fid)
{
	global $DATA_DIR, $PERMSTORE, $MIME_TYPES;
	$files = new Files($DATA_DIR . "/files.xml");
	$file = $files->getFile($fid);
	
	$filename = $PERMSTORE . "/" . $file->fid;
	
	$download = false;
	foreach($MIME_TYPES as $m) {
		if($m->name == $file->mimetype) $download = !$m->show;
	}
	
	//header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	header('Content-Description: File Transfer');
	header('Content-Type: ' . $file->mimetype);
	header('Content-Length: ' . filesize($filename));
	
	if($download) header('Content-Disposition: attachment; filename=' . basename($file->name));
	else header('Content-Disposition: inline; filename=' . basename($file->name));
	
	readfile($filename); 
}

?>