setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
/* If there is an error an exception is thrown */
echo 'Connection failed
';
echo 'Error number: ' . $e->getCode() . '
';
echo 'Error message: ' . $e->getMessage() . '
';
die();
}
// echo 'Successfully connected!'.PHP_EOL;
/////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// OUTPUT TORRENT DATA //////////////////////////////////////////
/* Query to select all torrents from your database */
$query = "SELECT * FROM torrents ORDER BY id ASC"; // CHANGE_THIS
/* Query to select torrents uploaded in last hour from your database */
// $query = "SELECT * FROM torrents WHERE upload_time > DATE_SUB(NOW(), INTERVAL 1 HOUR) ORDER BY id ASC";
try
{
/* Prepare step */
$res = $pdo->prepare($query);
/* Execute step */
$res->execute();
}
catch (PDOException $e)
{
/* If there is an error an exception is thrown */
echo 'Query error
';
echo 'Error number: ' . $e->getCode() . '
';
echo 'Error message: ' . $e->getMessage() . '
';
die();
}
// get torrents data from database
$torrents = $res->fetchAll(PDO::FETCH_ASSOC);
$saveTxtFile = $saveFolder.$saveFileName;
// open txt file to write torrents data
$fh = fopen($saveTxtFile, 'w+') or die("can't open file");
// loop to write each torrent to txt file
foreach ($torrents as $key => $value) {
/*
######################################## OUTPUT DATA ########################################
INFO_HASH - Torrent infohash
example: 092358777175c4306602f9b1b523738df4b4610b
TORRENT_TITLE - Torrent title
example: Bitcoin Core 25.0
TORRENT_CATEGORY - Torrent category and subcategory if any
example 1: PC > Software
example 2: Software
TORRENT_INFO_LINK - HTTPS link that has information on torrent and .torrent download links or magnet link
example: https://your-website.com/torrent-details/1234/Bitcoin-core-25
TORRENT_FILE_DOWNLOAD_LINK - .torrent file download link, if you do not save and host .torrent file you can put value NO_TORRENT_FILE, or use one of free .torrent hosting websites
example 1: https://your-website.com/torrent/bitcoin-25.0.torrent
example 2: https://bitcoin.org/bin/bitcoin-core-25.0/bitcoin-25.0.torrent
example 3: https://itorrents.org/torrent/092358777175C4306602F9B1B523738DF4B4610B.torrent
example 4: https://torrage.info/torrent.php?h=092358777175C4306602F9B1B523738DF4B4610B
example 5: https://btcache.me/torrent/092358777175C4306602F9B1B523738DF4B4610B
example 6: NO_TORRENT_FILE
###############################################################################################
!!! All fields are required. !!!
OUTPUT LINE FORMAT:
INFO_HASH|TORRENT_TITLE|TORRENT_CATEGORY|TORRENT_INFO_LINK|TORRENT_FILE_DOWNLOAD_LINK
EXAMPLES:
092358777175c4306602f9b1b523738df4b4610b|Bitcoin Core 25.0|PC > Software|https://your-website.com/torrent-details/1234/Bitcoin-core-25|https://itorrents.org/torrent/092358777175C4306602F9B1B523738DF4B4610B.torrent
OR
092358777175c4306602f9b1b523738df4b4610b|Bitcoin Core 25.0|Software|https://your-website.com/torrent-details/1234/Bitcoin-core-25|NO_TORRENT_FILE
*/
$dataToWrite =
$value["INFO_HASH"].'|'. // INFO_HASH - CHANGE_THIS
str_replace("|", " ", $value["TORRENT_TITLE"]).'|'. // TORRENT_TITLE - make sure to replace "|" character in name - CHANGE_THIS
$value["TORRENT_CATEGORY"] . " > " . $value["TORRENT_SUB_CATEGORY"].'|'. // TORRENT_CATEGORY - CHANGE_THIS
'https://your-website.com/torrent-details/'.$value["ID"].'/|'. // TORRENT_INFO_LINK - CHANGE_THIS
'https://itorrents.org/torrent/'.strtoupper($value["INFO_HASH"]).'.torrent'."\n"; // TORRENT_FILE_DOWNLOAD_LINK - CHANGE_THIS
// write torrent information line
fwrite($fh, $dataToWrite);
}
// close txt file
fclose($fh);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// COMPRESS OUTPUT TXT FILE //////////////////////////////////////////
// We recommend METHOD 2 on linux servers, if you have exec disabled or do not have gzip then leave METHOD 1
$gzMethod = 1; // CHANGE_THIS
// METHOD 1
if($gzMethod == 1){
$fp = fopen($saveTxtFile, "r");
$txtFiledata = fread ($fp, filesize($saveTxtFile));
fclose($fp);
$zp = gzopen($saveTxtFile.".gz", "w9");
gzwrite($zp, $txtFiledata);
gzclose($zp);
}
// METHOD 2
if($gzMethod == 2){
exec('gzip '.$saveTxtFile);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// delete .txt file
unlink($saveTxtFile);
?>