aboutsummaryrefslogtreecommitdiff
path: root/thumbnail.php
blob: 0e6142cbb16f0ce4048ae5fb1e22da9003af6e2c (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
<?php

	/**
	 * Elgg file thumbnail
	 * 
	 * @package ElggFile
	 * @author Curverider Ltd
	 * @copyright Curverider Ltd 2008
	 * @link http://elgg.com/
	 */

	// 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');
		if ($size != 'small') {
			$size = 'large';
		}
		
	// Get file entity
		if ($file = get_entity($file_guid)) {
			if ($file->getSubtype() == "image") {					
					// Get file thumbnail
						if ($size == "small") {
							$thumbfile = $file->smallthumb;
						} else {
							$thumbfile = $file->largethumb;
						}
						
					// 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();
						}
			} //end subtype comparison
		} //end get_entity

	// Open error image if file was not found
	if (!isset($contents) || is_null($contents) || $file->getSubtype()!='image') {
		//$vars['url'].'mod/tidypics/graphics/img_error.jpg
		forward('mod/tidypics/graphics/img_error.jpg');
	} //end of default error image

	// Return the thumbnail and exit
		header("Content-type: image");
		echo $contents;
		exit;
?>