-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.php
72 lines (61 loc) · 1.95 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
if(isset($_GET['error'])) die("Please use get.php");
$noAutoHeader = TRUE;
$noViewCount = TRUE;
$noOnlineUsers = TRUE;
$noFooter = TRUE;
$ajax = TRUE;
include("lib/common.php");
$full = GetFullURL();
$here = substr($full, 0, strrpos($full, "/"))."/";
if(isset($_GET['id']))
$entry = Query("select * from uploader where id = ".(int)$_GET['id']);
else if(isset($_GET['file']))
$entry = Query("select * from uploader where filename = '".justEscape($_GET['file'])."'");
else
die("Nothing specified.");
if(NumRows($entry))
{
$entry = Fetch($entry);
if($entry['private'])
$path = "uploader/".$entry['user']."/".$entry['filename'];
else
$path = "uploader/".$entry['filename'];
if(!file_exists($path))
die("No such file.");
$fsize = filesize($path);
$parts = pathinfo($path);
$ext = strtolower($parts["extension"]);
$download = true;
switch ($ext)
{
case "gif": $ctype="image/gif"; $download = false; break;
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 "swf": $ctype="application/x-shockwave-flash"; $download = false; break;
case "pdf": $ctype="application/pdf"; $download = false; break;
default: $ctype="application/force-download"; break;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: ".$ctype);
if($download)
header("Content-Disposition: attachment; filename=\"".$entry['filename']."\";");
else
header("Content-Disposition: filename=\"".$entry['filename']."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
readfile($path);
//header('Content-Disposition: attachment; filename="downloaded.pdf"');
}
else
{
die(__("No such file."));
}
?>