Fix calendar sidebar issue - changed holder from 'contentholder' to 'sidebarholder'
[elgg.git] / _files / icon.php
blob3fdb7c662ed2541f9561c84e6cc7f00f9c8e5925
1 <?php
3 // Icon script
5 // Run includes
6 require("../includes.php");
8 // Initialise functions for user details, icon management and profile management
9 run("userdetails:init");
10 run("profile:init");
11 run("files:init");
13 // If an ID number for the file has been specified ...
15 if (isset($_REQUEST['id'])) {
16 $id = (int) $_REQUEST['id'];
18 // ... and the file exists ...
20 $file = db_query("select location, access, originalname from files where ident = $id");
21 if (sizeof($file) > 0) {
23 $file = $file[0];
25 if (run("users:access_level_check",$file->access) == true) {
27 // Send 304s where possible, rather than spitting out the file each time
28 $if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
30 $tstamp = filemtime(path . $file->location);
31 $lm = gmdate("D, d M Y H:i:s", $tstamp) . " GMT";
33 if ($if_modified_since == $lm) {
34 header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
35 exit;
38 // Send last-modified header to enable if-modified-since requests
39 if ($tstamp < time()) {
40 header("Last-Modified: " . $lm);
43 // Then output some appropriate headers and send the file data!
45 $mimetype = run("files:mimetype:determine",$file->originalname);
46 if ($mimetype == false) {
47 $mimetype = "application/octet-stream";
49 if ($mimetype == "image/jpeg" || $mimetype == "image/png") {
50 $icon = url . "units/phpthumb/phpThumb.php?w=90&src=" . urlencode(path . $file->location);
51 $mimetype = "image/jpeg";
52 } else {
53 $mimetype = "image/png";
54 $icon = path . "_files/file.png";
57 // "Cache-Control: private" to allow a user's browser to cache the file, but not a shared proxy
58 // Also to override PHP's default "DON'T EVER CACHE THIS EVER" header
59 header("Cache-Control: private");
61 header("Content-type: $mimetype");
62 readfile($icon);