-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetattachment.php
38 lines (33 loc) · 1.02 KB
/
getattachment.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
<?php
require_once("include/bittorrent.php");
dbconn();
loggedinorreturn();
parked();
$id = (int)$_GET["id"];
if (!$id)
die('Invalid id.');
$dlkey = $_GET["dlkey"];
if (!$dlkey)
die('Invalid key');
$res = sql_query("SELECT * FROM attachments WHERE id = ".sqlesc($id)." AND dlkey = ".sqlesc($dlkey)." LIMIT 1") or sqlerr(__FILE__, __LINE__);
$row = _mysql_fetch_assoc($res);
if (!$row)
die('No attachment found.');
$filelocation = $httpdirectory_attachment."/".$row['location'];
if (!is_file($filelocation) || !is_readable($filelocation))
die('File not found or cannot be read.');
$f = fopen($filelocation, "rb");
if (!$f)
die("Cannot open file");
header("Content-Length: " . $row['filesize']);
header("Content-Type: application/octet-stream");
header_download_file($row['filename']);
do
{
$s = fread($f, 4096);
print($s);
} while (!feof($f));
fclose($f);
sql_query("UPDATE attachments SET downloads = downloads + 1 WHERE id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$Cache->delete_value('attachment_'.$dlkey.'_content');
exit;