root/releases/0.301/_files/icon.php

Revision 11, 2.1 kB (checked in by sven, 3 years ago)

snapshot of elgg 0.301

Line 
1 <?php
2
3     // Download script
4     // Usage: http://URL/{username}/files/{folder_id}/{file_id}/{filename}
5     
6     // Run includes
7         require("../includes.php");
8         
9     // Initialise functions for user details, icon management and profile management
10         run("userdetails:init");
11         run("profile:init");
12         run("files:init");
13         
14     // If an ID number for the file has been specified ...
15     
16         if (isset($_REQUEST['id'])) {
17             $id = (int) $_REQUEST['id'];
18             
19     // ... and the file exists ...
20             
21             $file = db_query("select location, access, originalname from files where ident = $id");
22             if (sizeof($file) > 0) {
23                 
24                 $file = $file[0];
25                                 
26                     if (run("users:access_level_check",$file->access) == true) {
27
28     // Send 304s where possible, rather than spitting out the file each time
29                         $if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
30                         
31                         $tstamp = filemtime($file->location);
32                         $lm = gmdate("D, d M Y H:i:s", $tstamp) . " GMT";
33                         
34                         if ($if_modified_since == $lm) {
35                             header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
36                             exit;
37                         }
38
39     // Send last-modified header to enable if-modified-since requests
40                         if ($tstamp < time()) {
41                             header("Last-Modified: " . $lm);
42                         }
43                         
44     // Then output some appropriate headers and send the file data!
45     
46                         $mimetype = run("files:mimetype:determine",$file->originalname);
47                         if ($mimetype == false) {
48                             $mimetype = "application/octet-stream";
49                         }
50                         if ($mimetype == "image/jpeg" || $mimetype == "image/png") {
51                             $icon = url . "units/phpthumb/phpThumb.php?w=90&src=" . urlencode($file->location);
52                             $mimetype = "image/jpeg";
53                         } else {
54                             $mimetype = "image/png";
55                             $icon = path . "_files/file.png";
56                         }
57
58     // "Cache-Control: private" to allow a user's browser to cache the file, but not a shared proxy
59     // Also to override PHP's default "DON'T EVER CACHE THIS EVER" header
60                         header("Cache-Control: private");
61                         
62                         header("Content-type: $mimetype");
63                         readfile($icon);
64                         
65                     }
66                     
67                 }
68             }
69
70 ?>
Note: See TracBrowser for help on using the browser.