root/releases/0.6/_files/icon.php

Revision 296, 2.1 kB (checked in by carmartin, 3 years ago)

Includes should use full path given that we know where things are. Patch 1.

  • Property svn:eol-style set to native
Line 
1 <?php
2
3 // Icon script
4
5 // Run includes
6 require_once(dirname(dirname(__FILE__))."/includes.php");
7
8 // Initialise functions for user details, icon management and profile management
9 run("userdetails:init");
10 run("profile:init");
11 run("files:init");
12
13 // If an ID number for the file has been specified ...
14 $id = optional_param('id',0,PARAM_INT);
15 if (!empty($id)) {
16     // ... and the file exists ...
17     if ($file = get_record('files','ident',$id)) {
18         if (run("users:access_level_check",$file->access) == true) {
19             // Send 304s where possible, rather than spitting out the file each time
20             $if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
21             
22             $tstamp = filemtime($CFG->dataroot. $file->location);
23             $lm = gmdate("D, d M Y H:i:s", $tstamp) . " GMT";
24             
25             if ($if_modified_since == $lm) {
26                 header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
27                 exit;
28             }
29             
30             // Send last-modified header to enable if-modified-since requests
31             if ($tstamp < time()) {
32                 header("Last-Modified: " . $lm);
33             }
34             
35             // Then output some appropriate headers and send the file data!
36             require_once($CFG->dirroot.'/lib/filelib.php');
37             $mimetype = mimeinfo('type',$file->originalname);
38             if ($mimetype == "image/jpeg" || $mimetype == "image/png") {
39                 $icon = url . "units/phpthumb/phpThumb.php?w=90&src=" . urlencode($CFG->dataroot . $file->location);
40                 $mimetype = "image/jpeg";
41             } else {
42                 $mimetype = "image/png";
43                 $icon = path . "_files/file.png";
44             }
45             
46             // "Cache-Control: private" to allow a user's browser to cache the file, but not a shared proxy
47             // Also to override PHP's default "DON'T EVER CACHE THIS EVER" header
48             header("Cache-Control: private");
49             
50             header("Content-type: $mimetype");
51             readfile($icon);
52             
53         }
54     }
55 }
56
57 ?>
Note: See TracBrowser for help on using the browser.