-
Notifications
You must be signed in to change notification settings - Fork 549
/
do-download.inc
40 lines (35 loc) · 1.08 KB
/
do-download.inc
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
<?php
/*
This code redirects the user to the exact file to
download, and logs the download if it's something
we would like to know about (PHP binary or source).
*/
function get_actual_download_file($file)
{
// Could be a normal download or a manual download file
$possible_files = [$file => true, "manual/$file" => false];
// Find out what is the exact file requested
$found = false;
foreach ($possible_files as $name => $log) {
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . '/distributions/' . $name)) {
$found = $name;
break;
}
}
return $found;
}
// Download a file from a mirror site
function download_file($mirror, $file): void
{
// Redirect to the particular file
if (!headers_sent()) {
status_header(302);
header('Location: ' . $mirror . 'distributions/' . $file);
} else {
exit("Unable to serve you the requested file for download");
}
// Try to flush output, and make the browser really
// download the file, even if the log server is down
echo " ";
flush();
}