root/devel/mod/file/icon.php

Revision 1539, 2.3 kB (checked in by renato, 1 year ago)

Setting prop svn:eol-style in LOTS of files.

  • 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 global $CFG;
14
15 // If an ID number for the file has been specified ...
16 $id = optional_param('id',0,PARAM_INT);
17 $w = optional_param('w',90,PARAM_INT);
18 $h = optional_param('h',90,PARAM_INT);
19
20 if (!empty($id)) {
21     // ... and the file exists ...
22     if ($file = get_record('files','ident',$id)) {
23         if ($file->access == 'PUBLIC' || run("users:access_level_check",$file->access) == true) {
24             
25             require_once($CFG->dirroot . 'lib/filelib.php');
26             require_once($CFG->dirroot . 'lib/iconslib.php');
27             
28             // images most likely don't want compressing, and this will kill the Vary header
29             if (function_exists('apache_setenv')) { // apparently @ isn't enough to make php ignore this failing
30                 @apache_setenv('no-gzip', '1');
31             }
32             
33             if ($file->access == 'PUBLIC') {
34                 header("Pragma: public");
35                 header("Cache-Control: public");
36             } else {
37                 // "Cache-Control: private" to allow a user's browser to cache the file, but not a shared proxy
38                 // Also to override PHP's default "DON'T EVER CACHE THIS EVER" header
39                 header("Cache-Control: private");
40             }
41             
42             $mimetype = mimeinfo('type',$file->originalname);
43             if ($mimetype == "image/jpeg" || $mimetype == "image/png" || $mimetype == "image/gif") {
44                 // file is an image
45                 
46                 $phpthumbconfig = array();
47                 $phpthumbconfig['w'] = $w;
48                 $phpthumbconfig['h'] = $h;
49                 
50                 $filelocation = file_cache($file);
51                 spit_phpthumb_image($filelocation, $phpthumbconfig);
52                 
53             } else {
54                 
55                 // file is a file
56                 header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently"); //permanent because the user's file can't change and keep the same id
57                 header("Location: " . $CFG->wwwroot . 'mod/file/file.png');
58                 die();
59                 
60             }
61             
62         }
63     }
64 }
65
66 ?>
Note: See TracBrowser for help on using the browser.