root/releases/0.673/_files/icon.php

Revision 740, 2.0 kB (checked in by ben, 2 years ago)

Fixed icon issue in files unit.

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