mulekula
10-31-2011, 04:47 PM
Hi all!
Please help me finish script that would have counted the torrent file size that's what I tried to do:
$new_torr_file_size = '.$new_torr.'; //$new_torr_filename = "torrent/".$_FILES['file']['name'];
if ($new_torr_file_size>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
$theDiv = $theFileSize / 1000000;
$new_torr_file_size = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces)
} else { //OTHERWISE DISPLAY AS KB
$theDiv = $theFileSize / 1000;
$new_torr_file_size = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces)
}
Here's the script that Pars information from the file:
require_once './BEncoder.inc.php';
$my_tracker_url = 'http://ya.ru/';
$torr_filename = 'http://torrents.thepiratebay.org/6687573/Rurouni_Kenshin_-_Artbook_(825x1200)_[JPG]_TNT_Village.6687573.TPB.torrent';
$new_torr_filename = './456.torrent';
// Read torrent file
$torr_data = @file_get_contents($torr_filename);
if ($torr_data!==false && !empty($torr_data))
{
try {
$encoder = new BEncoder ();
// decode input torrent file
$torr_array = $encoder->decode ($torr_data);
if (!isset($torr_array["announce-list"]))
{// if torrent dont have list, create it and add to it main announcer
$torr_array["announce-list"][] = array($torr_array["announce"]);
}
// add new tracker
$torr_array["announce-list"][] = array($my_tracker_url);
$new_torr = $encoder->encode($torr_array);
if (!file_put_contents($new_torr_filename,$new_torr))
{
echo 'cant write new torrent file <b>' . $new_torr_filename . '</b>';
}
} catch (Exception $e) {
echo 'wrong format in torrent file <b>' . $torr_filename . '</b>:<br /><b>'. $e->getMessage() .'</b>';
}
}
else
{
echo ('Cannot load file <b>' . $torr_filename . '</b>');
}
I hope for your help!
PS: I am from Ukraine, so sorry for my English ^_^
Please help me finish script that would have counted the torrent file size that's what I tried to do:
$new_torr_file_size = '.$new_torr.'; //$new_torr_filename = "torrent/".$_FILES['file']['name'];
if ($new_torr_file_size>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
$theDiv = $theFileSize / 1000000;
$new_torr_file_size = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces)
} else { //OTHERWISE DISPLAY AS KB
$theDiv = $theFileSize / 1000;
$new_torr_file_size = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces)
}
Here's the script that Pars information from the file:
require_once './BEncoder.inc.php';
$my_tracker_url = 'http://ya.ru/';
$torr_filename = 'http://torrents.thepiratebay.org/6687573/Rurouni_Kenshin_-_Artbook_(825x1200)_[JPG]_TNT_Village.6687573.TPB.torrent';
$new_torr_filename = './456.torrent';
// Read torrent file
$torr_data = @file_get_contents($torr_filename);
if ($torr_data!==false && !empty($torr_data))
{
try {
$encoder = new BEncoder ();
// decode input torrent file
$torr_array = $encoder->decode ($torr_data);
if (!isset($torr_array["announce-list"]))
{// if torrent dont have list, create it and add to it main announcer
$torr_array["announce-list"][] = array($torr_array["announce"]);
}
// add new tracker
$torr_array["announce-list"][] = array($my_tracker_url);
$new_torr = $encoder->encode($torr_array);
if (!file_put_contents($new_torr_filename,$new_torr))
{
echo 'cant write new torrent file <b>' . $new_torr_filename . '</b>';
}
} catch (Exception $e) {
echo 'wrong format in torrent file <b>' . $torr_filename . '</b>:<br /><b>'. $e->getMessage() .'</b>';
}
}
else
{
echo ('Cannot load file <b>' . $torr_filename . '</b>');
}
I hope for your help!
PS: I am from Ukraine, so sorry for my English ^_^