summaryrefslogtreecommitdiff
path: root/forum/utils/file.php
blob: 25cb4c25d0c1cf57197fb5389d0bc8bd7a8ac61a (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
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
<?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); 
}

function getFilePreview($fid)
{
	global $DATA_DIR, $PERMSTORE, $MIME_TYPES;
	$files = new Files($DATA_DIR . "/files.xml");
	$file = $files->getFile($fid);
	
	$filename = $PERMSTORE . "/" . $file->fid;
	
	if(strstr($file->mimetype, "image")) {
		header('Content-Description: File Transfer');
		header('Content-Type: ' . $file->mimetype);
		header('Content-Length: ' . filesize($filename));
		header('Content-Disposition: inline; filename=' . basename($file->name));
		readfile($filename); 
	} else {
		header("Content-type: image/png");
		$im = @imagecreate(8 + strlen($file->name) * 5, 20)
			or die("Cannot Initialize new GD image stream");
		$background_color = imagecolorallocate($im, 0, 0, 0);
		$text_color = imagecolorallocate($im, 233, 14, 91);
		imagestring($im, 1, 5, 5,  $file->name, $text_color);
		imagepng($im);
		imagedestroy($im);
	}
}

?>