Here is the working and testing and secured AJAX PDO Torrent Uploader. Wrote for my site as we are in strong need for something better and aim to introduce multi-uploading after this post.
Users like it. It makes my life a lot easier as i don't have to spend endless time filling out every torrent, deal with constant errors of who knows what (torrents-upload.php) and took forever to parse torrents and handle images on high end hardware. So here we have it.
Create ajax_torrentupload.php and add this:
Now add this to header.php
Thats it! Just make sure you have jQuery already, and your good to go. This will probably end up on a function someplace far away, but the AJAX is brilliant.
[ATTACH type="full" alt="NewUploader.png"]5565[/ATTACH]
On my end. Your use may greatly vary, but this is what I'm using it for. Use clicks UPLOAD, and it goes to torrent-edit immediately. File downloading is flawless, as we had to ensure our .torrent renames to the new table ID for downloading (download.php) so out of the box compatible.
You can literally take this, and create upload-only torrent tracker posting to this script (dump it in a HTML form page or menu), make a PHP index table of recent uploads and if your feeling creative, follow a signup/login script tutorial for MySQL (really easy, I’ve done it twice), create your users table and upload. You can use your existing torrent table (with all the data), and plug it into the same index. Read from it. It’s too easy. As you see, this script is portable. I did not find a single search engine link to exactly this, why? I dunno.
With this you don’t need TT anymore really, because you plug in everything around it in a template utilizing this uploader. This is the whole reason for using torrent trader, is it’s upload function and announce/web tracker features, The rest is expected, and great but not really necessary, technically.
I will make a zip and create what I just explained. It will work for you, upload your first torrent and scrape it as you visit ?
Users like it. It makes my life a lot easier as i don't have to spend endless time filling out every torrent, deal with constant errors of who knows what (torrents-upload.php) and took forever to parse torrents and handle images on high end hardware. So here we have it.
Create ajax_torrentupload.php and add this:
<?
/* AJAX Torrent Uploader - May 27, 2020
Using Parsing class - Torrent()->object()
Replaces old torrents-upload.php and related classes: BDecode(), BEncode()
Triggered by AJAX call.
Accepts .torrent: Parses data => Inserts to DB => Redirects to edit page
STorrents @ TorrentTrader.xyz
*/
// Required for successful redirect
error_reporting(0);
$blacklist = array(
".php",
".phtml",
".php3",
".php4",
".pl",
".html",
".cgi",
".htaccess"
);
foreach ($blacklist as $item) {
if (preg_match("/$item$/i", $_FILES['file']['name'])) {
exit;
}
}
if (0 < $_FILES['file']['error']) {
echo 'Error: ' . $_FILES['file']['error'] . '<br>';
} else {
require_once('backend/class.parse.php');
$parsepath = 'uploads/' . $_FILES['file']['name'];
$torrent = new Torrent($parsepath);
$torr_hash = $torrent->hash_info();
$torr_announce = $torrent->announce();
$torr_size = $torrent->size();
$torr_saveas = $torrent->name();
$torr_private = $torrent->is_private() ? 'yes' : 'no';
$userid = (int) $_POST['userid'];
require_once 'backend/functions.php';
try {
$dsn = 'mysql:dbname=database;host=localhost';
$user = 'username';
$password = 'password';
$conn = new PDO($dsn, $user, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
die('Error: Unable to connect to database');
}
$sql = "INSERT INTO torrents (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, announce, external, nfo, torrentlang, anon, visible, last_action)
VALUES ('" . $torr_saveas . ".torrent', " . $userid . ", '" . $torr_saveas . "', '" . $torr_saveas . " is currently being updated.', '', '', '1', NOW(), '" . $torr_hash . "', '" . $torr_size . "', 3, '" . $torr_saveas . ".torrent', '" . $torr_announce . "', '" . $torr_private . "', 'no', 1, 'no', 'yes', NOW())";
$query = $conn->prepare($sql);
$query->execute();
$id = $conn->lastInsertId();
$rename = "uploads/" . $id . ".torrent";
if (move_uploaded_file($_FILES['file']['tmp_name'], $rename)) {
echo $site_config["SITEURL"] . '/torrent-edit.php?id=' . $id;
}
}
?>
Now add this to header.php
<script>
// AJAX Torrent Upload
$(document).ready(function(a) {
$("#form-torupload").on("change", function(a) {
var file_data = $('#uploadTorrent').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: "ajax_torrentupload.php",
dataType: 'html',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: "POST",
beforeSend: function () {
$("#upload-progress").html("Uploading Torrent...").delay(3000).fadeIn().delay(4000).fadeOut();
},
success: function(torrent_complete){
window.location.href = torrent_complete;
}
});
});
});
</script>
Thats it! Just make sure you have jQuery already, and your good to go. This will probably end up on a function someplace far away, but the AJAX is brilliant.
[ATTACH type="full" alt="NewUploader.png"]5565[/ATTACH]
On my end. Your use may greatly vary, but this is what I'm using it for. Use clicks UPLOAD, and it goes to torrent-edit immediately. File downloading is flawless, as we had to ensure our .torrent renames to the new table ID for downloading (download.php) so out of the box compatible.
You can literally take this, and create upload-only torrent tracker posting to this script (dump it in a HTML form page or menu), make a PHP index table of recent uploads and if your feeling creative, follow a signup/login script tutorial for MySQL (really easy, I’ve done it twice), create your users table and upload. You can use your existing torrent table (with all the data), and plug it into the same index. Read from it. It’s too easy. As you see, this script is portable. I did not find a single search engine link to exactly this, why? I dunno.
With this you don’t need TT anymore really, because you plug in everything around it in a template utilizing this uploader. This is the whole reason for using torrent trader, is it’s upload function and announce/web tracker features, The rest is expected, and great but not really necessary, technically.
I will make a zip and create what I just explained. It will work for you, upload your first torrent and scrape it as you visit ?