-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpic.php
54 lines (40 loc) · 1.68 KB
/
pic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
require_once('../../config.php');
require_once($CFG->libdir . '/filelib.php');
require_once('lib.php');
disable_debugging();
$argument = get_file_argument('pic.php');
$thumb = optional_param('thumb', 0, PARAM_BOOL);
$forcedownload = optional_param('forcedownload', 0, PARAM_BOOL);
if (! $argument) {
error('No valid arguments supplied or incorrect server configuration');
} else if ($argument{0} != '/') {
error('No valid arguments supplied, path does not start with slash!');
}
$args = explode('/', trim($argument, '/'));
if (count($args) < 2) {
error('Not enough valid arguments supplied');
}
if (! $gallery = get_record('lightboxgallery', 'id', $args[0])) {
error('Course module is incorrect');
}
if (! $course = get_record('course', 'id', $gallery->course)) {
error('Course is misconfigured');
}
if (! ($gallery->ispublic || (lightboxgallery_rss_enabled() && $gallery->rss))) {
require_login($course->id);
}
$filename = clean_param($args[1], PARAM_PATH);
if ($thumb) {
$path = $CFG->dataroot . '/' . $course->id . '/' . $gallery->folder . '/_thumb/' . $filename . '.jpg';
} else {
$path = $CFG->dataroot . '/' . $course->id . '/' . $gallery->folder . '/' . $filename;
}
$lifetime = get_config('lightboxgallery', 'imagelifetime');
if (! file_exists($path)) {
header('HTTP/1.0 404 not found');
print_error('filenotfound', 'error', $CFG->wwwroot . '/course/view.php?id=' . $course->id);
}
session_write_close();
send_file($path, $filename, $lifetime, $CFG->filteruploadedfiles, false, $forcedownload);
?>