| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
require_once(dirname(dirname(__FILE__))."/includes.php"); |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
run("userdetails:init"); |
|---|
| 11 |
run("profile:init"); |
|---|
| 12 |
run("files:init"); |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
$id = optional_param('id',0,PARAM_INT); |
|---|
| 16 |
if (!empty($id)) { |
|---|
| 17 |
|
|---|
| 18 |
if ($file = get_record('files','ident',$id)) { |
|---|
| 19 |
|
|---|
| 20 |
$files_name = optional_param('files_name'); |
|---|
| 21 |
$userid = user_info_username('ident', $files_name); |
|---|
| 22 |
if ($userid == $file->owner || $userid == $file->files_owner) { |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
if ($file->access == 'PUBLIC' || $file->owner == $_SESSION['userid'] || run("users:access_level_check",$file->access) == true) { |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
if ($file->access == 'PUBLIC') { |
|---|
| 29 |
header("Pragma: public"); |
|---|
| 30 |
header("Cache-Control: public"); |
|---|
| 31 |
} else { |
|---|
| 32 |
|
|---|
| 33 |
// Also to override PHP's default "DON'T EVER CACHE THIS EVER" header |
|---|
| 34 |
header("Cache-Control: private"); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
require_once($CFG->dirroot . 'lib/filelib.php'); |
|---|
| 38 |
$mimetype = mimeinfo('type',$file->location); |
|---|
| 39 |
|
|---|
| 40 |
if ($mimetype == "application/octet-stream") { |
|---|
| 41 |
header('Content-Disposition: attachment'); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
// partly because it's pointless, but mainly because some browsers |
|---|
| 46 |
// are thick. |
|---|
| 47 |
if (preg_match('#^(application.*zip|image/(png|jpeg|gif))$#', $mimetype)) { |
|---|
| 48 |
if (function_exists('apache_setenv')) { |
|---|
| 49 |
@apache_setenv('no-gzip', '1'); |
|---|
| 50 |
} |
|---|
| 51 |
} |
|---|
| 52 |
spitfile_with_mtime_check($CFG->dataroot . $file->location, $mimetype, $file->handler); |
|---|
| 53 |
} |
|---|
| 54 |
} |
|---|
| 55 |
} |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
?> |
|---|