rendered paste body@@ act=idx source/idx.php .torrent uploader
<?php if(!isset($is_loaded)){die('» Must be loaded from core');} ?>
<?php require_once(HEADER); ?>
<?php
if($_POST['submit'] == 'Upload'){
if($_FILES['torrent']['type']=='application/x-bittorrent'){
$torrent['md5'] = md5_file($_FILES['torrent']['tmp_name']);
$torrent['name'] = basename($_FILES['torrent']['name'], '.torrent');
$torrent['size'] = $_FILES['torrent']['size'];
$torrent['hash'] = $_FILES['torrent']['tmp_name'];
$torrent['hash'] = file_get_contents($torrent['hash']);
$torrent['ohash'] = $torrent['hash'];
$torrent['hash'] = base64_encode($torrent['hash']);
$mysql = new MySql;
$mysql->FieldsRequest(array('id','name','md5'));
$mysql->QueryRequest("SELECT * FROM torrents WHERE md5='{$torrent['md5']}' LIMIT 1");
if($mysql->outputfields['md5'][0] == $torrent['md5']){
$template['error'] = "Oops!, the file that you are trying to upload already exist in out database under the name <a href=\"index.php?act=torrent&torrent={$mysql->outputfields['md5'][0]}\">{$mysql->outputfields['name'][0]}.torrent</a>";
}else{
$mysql = new MySql;
$mysql->QueryInsert("INSERT INTO torrents (name,hash,size,md5) VALUES ('{$torrent['name']}','{$torrent['hash']}','{$torrent['size']}','{$torrent['md5']}');");
$template['success'] = "<a href=\"index.php?act=torrent&torrent={$torrent['md5']}\">{$torrent['name']}.torrent</a> Succesfully uploaded!";
}
}else{
$template['error'] = "Oops!, it seems that the file you are trying to upload is not a .torrent file. Please check the file and try again";
}
}
?>
<form enctype="multipart/form-data" id="upload" name="upload" method="post" action="index.php?act=idx">
Torrent:
<input type="file" id="torrent" name="torrent" />
<input type="submit" id="submit" name="submit" value="Upload" onSubmit="this.value='Uploading...'" />
<br />
<?= $template['error']; ?>
<?= $template['success']; ?>
</form>
<?php require_once(FOOTER); ?>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ act=torrent source/torrent.php .torrent downloader
<?php
if(isset($_GET['torrent'])){
$torrent['md5'] = $_GET['torrent'];
$mysql = new MySql;
$mysql->FieldsRequest(array('id','name','md5','hash','size'));
$mysql->QueryRequest("SELECT * FROM torrents WHERE md5='{$torrent['md5']}' LIMIT 1");
if(isset($mysql->outputfields['md5'][0])){
$torrent['name'] = "{$mysql->outputfields['name'][0]}.torrent";
$torrent['hash'] = $mysql->outputfields['hash'][0];
$torrent['hash'] = base64_decode($torrent['hash']);
$torrent['size'] = $mysql->outputfields['size'][0];
if(strlen($torrent['hash']) == $torrent['size']){
header("Content-length: {$torrent['size']}");
header("Content-type: application/x-bittorrent");
header("Content-Disposition: attachment; filename=\"{$torrent['name']}\"");
echo $torrent['hash'];
}else{
$template['error'] = "There seems to be a problem with <strong>{$torrent['name']}</strong> it may be corrupted.";
}
}else{
$template['error'] = "Oops!, it seems that the torrent you requested does not exist in our database.";
}
}else{
header("Location: index.php?act=idx");
exit;
}
if(isset($template['error'])){
echo $template['error'];
}
?>