-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdownloadsubs.php
55 lines (47 loc) · 1.84 KB
/
downloadsubs.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
<?php
require "include/bittorrent.php";
require_once("include/tjuip_helper.php");
dbconn();
global $CURUSER;
if (!$CURUSER) {
Header("Location: /");
die;
}
check_tjuip_or_warning($CURUSER);
$filename = $_GET["subid"];
$dirname = $_GET["torrentid"];
if (!$filename || !$dirname)
die("File name missing\n");
$filename = 0 + $filename;
$dirname = 0 + $dirname;
$res = sql_query("SELECT * FROM subs WHERE id=$filename") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res);
if (!$arr)
die("Not found\n");
sql_query("UPDATE subs SET hits=hits+1 WHERE id=$filename") or sqlerr(__FILE__, __LINE__);
$file = "$SUBSPATH/$dirname/$filename.$arr[ext]";
if (!is_file($file))
die("File not found\n");
$f = fopen($file, "rb");
if (!$f)
die("Cannot open file\n");
header("Content-Length: " . filesize($file));
header("Content-Type: application/octet-stream");
if (str_replace("Gecko", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
header("Content-Disposition: attachment; filename=\"$arr[filename]\" ; charset=utf-8");
} else if (str_replace("Firefox", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
header("Content-Disposition: attachment; filename=\"$arr[filename]\" ; charset=utf-8");
} else if (str_replace("Opera", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
header("Content-Disposition: attachment; filename=\"$arr[filename]\" ; charset=utf-8");
} else if (str_replace("IE", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
header("Content-Disposition: attachment; filename=" . str_replace("+", "%20", rawurlencode($arr['filename'])));
} else {
header("Content-Disposition: attachment; filename=" . str_replace("+", "%20", rawurlencode($arr['filename'])));
}
do {
$s = fread($f, 4096);
print($s);
} while (!feof($f));
//closefile($f);
exit;
?>