aboutsummaryrefslogtreecommitdiff
path: root/mod/file/thumbnail.php
blob: 987153aebbc6cdcc1767ecc86e4485440730f37a (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
58
59
60
61
62
63
64
65
66
<?php

/**
 * Elgg file thumbnail
 *
 * @package ElggFile
 */

// Get engine
require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

// Get file GUID
$file_guid = (int) get_input('file_guid',0);

// Get file thumbnail size
$size = get_input('size','small');

// Get file entity
if ($file = get_entity($file_guid)) {
		
	if ($file->getSubtype() == "file") {

		$simpletype = $file->simpletype;
		if ($simpletype == "image") {
				
			// Get file thumbnail
			switch ($size) {
				case "small":
					$thumbfile = $file->thumbnail;
					break;
				case "medium":
					$thumbfile = $file->smallthumb;
					break;
				case "large":
				default:
					$thumbfile = $file->largethumb;
					break;
			}

			// Grab the file
			if ($thumbfile && !empty($thumbfile)) {
				$readfile = new ElggFile();
				$readfile->owner_guid = $file->owner_guid;
				$readfile->setFilename($thumbfile);
				$mime = $file->getMimeType();
				$contents = $readfile->grabFile();
				
				// caching images for 10 days
				header("Content-type: $mime");
				header('Expires: ' . date('r',time() + 864000));
				header("Pragma: public", true);
				header("Cache-Control: public", true);
				header("Content-Length: " . strlen($contents));
				
				echo $contents;
				exit;
					
			}
				
		}

	}
		
}

?>