<?
require_once("include/bittorrent.inc.php");

$id = intval($id);

dbconn();

$res = mysql_query("SELECT 1 FROM torrents WHERE id = $id");
$row = mysql_fetch_array($res);

$fn = "$torrent_dir/$id.torrent";

if (!$row || !is_file($fn) || !is_readable($fn))
	httperr();

mysql_query("UPDATE torrents SET hits = hits + 1 WHERE id = $id");

header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
//header("Content-Disposition: filename=\"" . htmlentities(urlencode($file)) . "\"");
//header("Content-Description: ". htmlentities(urlencode($file)));
//header("Content-Type: application/x-bittorrent");

header("Content-disposition: filename=".$file);
header("Content-Type: application/x-bittorrent");
readfile($fn);
?>
