forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownload.php
More file actions
69 lines (54 loc) · 1.79 KB
/
download.php
File metadata and controls
69 lines (54 loc) · 1.79 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Serves the public downloads.
*/
use ProjectSend\Classes\Download;
require_once 'bootstrap.php';
$page_id = 'public_download';
if (!empty($_GET['token']) && !empty($_GET['id'])) {
$token = htmlentities($_GET['token']);
$file_id = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
if (!is_numeric($_GET['id'])) {
exit;
}
$can_download = false;
$can_view = false; // Can only view information about the file, not download it
$file = new \ProjectSend\Classes\Files($file_id);
if ($file->public_token != $token || $file->expired == true) {
exit_with_error_code(403);
}
if ($file->public == 1 && $file->public_token == $token) {
$can_download = true;
$can_view = true;
}
if (get_option('enable_landing_for_all_files') == '1') {
$can_view = true;
} else {
if ($file->public == 0) {
exit_with_error_code(403);
}
}
if ($can_download == true) {
if (isset($_GET['download'])) {
record_new_download(0, $file->id);
/** Record the action log */
$logger = new \ProjectSend\Classes\ActionsLog;
$new_record_action = $logger->addEntry([
'action' => 37,
'owner_user' => null,
'owner_id' => 0,
'affected_file' => $file->id,
'affected_file_name' => $file->filename_original,
]);
// DOWNLOAD
$process = new Download;
$alias = $process->getAlias($file);
$process->serveFile($file->full_path, $file->filename_unfiltered, $alias);
exit;
}
}
} else {
exit_with_error_code(403);
}
$dont_redirect_if_logged = 1;
require get_template_file_location('public-download.php');