aboutsummaryrefslogtreecommitdiff
path: root/mod/file/thumbnail.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/file/thumbnail.php')
-rw-r--r--mod/file/thumbnail.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/mod/file/thumbnail.php b/mod/file/thumbnail.php
new file mode 100644
index 000000000..851f13a8f
--- /dev/null
+++ b/mod/file/thumbnail.php
@@ -0,0 +1,57 @@
+<?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');
+
+$file = get_entity($file_guid);
+if (!$file || $file->getSubtype() != "file") {
+ exit;
+}
+
+$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: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
+ header("Pragma: public", true);
+ header("Cache-Control: public", true);
+ header("Content-Length: " . strlen($contents));
+
+ echo $contents;
+ exit;
+ }
+}