root/releases/0.6rc2/_icons/icon.php

Revision 296, 2.6 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 // User icon serving script.
4 // Usage: http://URL/{username}/icons/{icon_id}
5
6 // Run includes
7 require_once(dirname(dirname(__FILE__))."/includes.php");
8 $textlib = textlib_get_instance();
9
10 // If an ID number for the file has been specified ...
11 $id = optional_param('id',0,PARAM_INT);
12 $default = false;
13 if (empty($id)) {
14     $default = true;
15 }
16 // ... and the file exists ...
17 if (!$file = get_record('icons','ident',$id)) {
18     $default = true;
19 }
20 // get the user who belongs to this icon..
21 if (empty($file) || !$user = get_record('users','ident',$file->owner)) {
22     $default = true;
23 }
24 if (empty($default)) {
25     $upload_folder = $textlib->substr($user->username,0,1);
26     $filepath = $CFG->dataroot . "icons/" . $upload_folder . "/" . $user->username . "/".$file->filename;
27     if (!file_exists($filepath)) {
28         $default = true;
29     }
30 }
31
32 if (!empty($default)) {
33     $filepath = path.'_icons/data/default.png';
34 }
35
36 $tstamp = filemtime($filepath);
37 $lm = gmdate("D, d M Y H:i:s", $tstamp) . " GMT";
38     
39 // Send 304s where possible, rather than spitting out the file each time
40 if (array_key_exists('HTTP_IF_MODIFIED_SINCE',$_SERVER)) {
41     $if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
42     if ($if_modified_since == $lm) {
43         header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
44         exit;
45     }
46 }
47
48 // Send last-modified header to enable if-modified-since requests
49 if ($tstamp < time()) {
50     header("Last-Modified: " . $lm);
51 }
52
53 // Then output some appropriate headers and send the file data!
54 require_once($CFG->dirroot.'lib/filelib.php');
55 $mimetype = mimeinfo('type',$file->filename);
56
57 // see if we must resize it.
58 $constraint1 = strtolower(optional_param('constraint1'));
59 $size1 = optional_param('size1');
60 $constraint2 = strtolower(optional_param('constraint2'));
61 $size2 = optional_param('size2');
62
63 $url $CFG->wwwroot.'units/phpthumb/phpThumb.php?src='.urlencode($filepath);
64 // if size == 100, leave it.
65 if (!empty($constraint1) && !empty($size1) && ($constraint1 == 'h' || $constraint1 = 'w') && $size1 != 100) {
66     $url .= '&'.$constraint1.'='.$size1;
67     $phpthumb = true;
68 }
69 if (!empty($constraint2) && !empty($size2) && ($constraint2 == 'h' || $constraint2 = 'w') && $size2 != 100) {
70     $url .= '&'.$constraint2.'='.$size2;
71     $phpthumb = true;
72 }
73 if (!empty($phpthumb)) {
74     header("Location: $url");
75     exit;
76 }
77 // "Cache-Control: private" to allow a user's browser to cache the file, but not a shared proxy
78 // Also to override PHP's default "DON'T EVER CACHE THIS EVER" header
79 header("Cache-Control: private");
80
81 header("Content-type: $mimetype");
82 readfile($filepath);
83             
84 ?>
Note: See TracBrowser for help on using the browser.