<?php if(!isset($is_loaded)){die('» Must be loaded from core');} ?>
<?php require_once(HEADER); ?>
<?php
if($_POST['submit'] == 'Upload'){
$torrent = pathinfo($_FILES['torrent']['name']);
if($_FILES['torrent']['type'] == 'application/x-bittorrent' || 'application/octet-stream'){
if($torrent['extension'] == 'torrent'){
$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']);
if(strpos($torrent['ohash'], 'd8:announce') !== false){
$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!";
$mysql->Query("OPTIMIZE TABLE torrents");
}
}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.";
}
}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.";
}
}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); ?>