|
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 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
require_once(dirname(dirname(__FILE__))."/includes.php"); |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
run("userdetails:init"); |
|---|
| 10 |
run("profile:init"); |
|---|
| 11 |
run("files:init"); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
$id = optional_param('id',0,PARAM_INT); |
|---|
| 15 |
if (!empty($id)) { |
|---|
| 16 |
|
|---|
| 17 |
if ($file = get_record('files','ident',$id)) { |
|---|
| 18 |
if (run("users:access_level_check",$file->access) == true) { |
|---|
| 19 |
|
|---|
| 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 |
|
|---|
| 31 |
if ($tstamp < time()) { |
|---|
| 32 |
header("Last-Modified: " . $lm); |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 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 |
|
|---|
| 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 |
?> |
|---|