All pastes #64911 Raw Edit

Stuff

public text v1 · immutable
#64911 ·published 2006-06-12 19:40 UTC
rendered paste body
<?php if(!isset($is_loaded)){die('&raquo 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['description'] = $_POST['description'];
			$torrent['tags'] = $_POST['tags'];
			$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&amp;torrent={$mysql->outputfields['md5'][0]}\">{$mysql->outputfields['name'][0]}.torrent</a>.";
				}else{
					$mysql = new MySql;
					$mysql->QueryInsert("INSERT INTO torrents (name,hash,size,md5,description,tags) VALUES ('{$torrent['name']}','{$torrent['hash']}','{$torrent['size']}','{$torrent['md5']}','{$torrent['description']}','{$torrent['tags']}');");
					$template['success'] = "<a href=\"index.php?act=parse&amp;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" /><br /><br />
  Description:<br />
  <textarea name="description" cols="70" rows="5"></textarea><br /><br />
  Tags: 
  <input type="text" name="tags" />Seperate each Tag with a comma.<br /><br />
  <input type="submit" id="submit" name="submit" value="Upload" onSubmit="this.value='Uploading...'" />
  <br />
  <?= $template['error']; ?>
  <?= $template['success']; ?>
</form>
<?php require_once(FOOTER); ?>