This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
get.php
57 lines (46 loc) · 1.81 KB
/
get.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
55
56
57
<?php
define('BLARG', 1);
include(__DIR__."/lib/common.php");
$entry = Fetch(Query("select * from {uploadedfiles} where id = {0}", $_GET['id']));
if (!$entry)
die(__("Unknown file ID."));
if ($entry['deldate'] != 0)
die(__("No such file."));
$path = DATA_DIR.'uploads/'.$entry['physicalname'];
if(!file_exists($path))
die(__("No such file."));
//Count downloads!
if (!$isBot)
Query("update {uploadedfiles} set downloads = downloads+1 where id = {0}", $entry['id']);
// TODO detect/store MIME type instead of all that junk?
$fsize = filesize($path);
$parts = pathinfo($entry['filename']);
$ext = strtolower($parts['extension']);
$download = true;
switch ($ext)
{
case "gif": $ctype="image/gif"; $download = false; break;
case 'bmp': $path = 'img/nobmp.png'; $fsize = filesize($path);
case "apng":
case "png": $ctype="image/png"; $download = false; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; $download = false; break;
case "css": $ctype="text/css"; $download = false; break;
case "txt": $ctype="text/plain"; $download = false; break;
case "pdf": $ctype="application/pdf"; $download = false; break;
case 'mp3': $ctype = 'audio/mpeg'; $download = false; break;
default: $ctype="application/force-download"; break;
}
$cachetime = 604800; // 1 week. Should be more than okay. Uploaded files aren't supposed to change.
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: private, post-check={$cachetime}, pre-check=999999999, min-fresh={$cachetime}, max-age={$cachetime}");
header("Content-Type: ".$ctype);
if($download)
header("Content-Disposition: attachment; filename=\"".addslashes($entry['filename'])."\";");
else
header("Content-Disposition: filename=\"".addslashes($entry['filename'])."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
readfile($path);
?>