Exemple #1
0
<?php 
include "bencode.php";
include "func.php";
include "config.php";
if (isset($_POST["submit"])) {
    if (isset($_FILES["fileToUpload"])) {
        $myfile = fopen($_FILES["fileToUpload"]["tmp_name"], "r") or die("Unable to open file!");
        $str_file = fread($myfile, filesize($_FILES["fileToUpload"]["tmp_name"]));
        fclose($myfile);
        $r = ben_decode($str_file);
        if (is_valid_torrent($r)) {
            $r[0]['announce'] = $config_announce;
            $r[0]['announce-list'] = 0;
            $str_file = ben_encode($r[0]['info']);
            $sha1_torrent = sha1('d' . $str_file . 'e');
            echo $sha1_torrent . "<br>";
            $str_file = ben_encode($r);
            $torrent_name = mysqli_real_escape_string($mysq_link, get_torrent_name($r));
            $sql = "INSERT INTO torrents (name, sha) VALUES ('{$torrent_name}', '{$sha1_torrent}')";
            if (mysqli_query($mysq_link, $sql)) {
                echo "New record created successfully";
                $myfile = fopen($config_upload_dir . $sha1_torrent . ".torrent", "w");
                fwrite($myfile, $str_file, strlen($str_file));
                fclose($myfile);
            } else {
                echo "Error: " . $sql . "<br>" . mysqli_error($mysq_link);
            }
        }
    }
}
Exemple #2
0
}
$sha = mysqli_real_escape_string($mysq_link, $_GET['torrent']);
$sql = "SELECT name, date FROM torrents WHERE sha='{$sha}'";
$result = mysqli_query($mysq_link, $sql);
if ($result && mysqli_num_rows($result) > 0) {
    if ($row = mysqli_fetch_assoc($result)) {
        echo 'Name: ';
        echo '<a href="' . $config_upload_dir . $sha . '.torrent">' . $row['name'] . '</a> ';
        echo '<a href="torrent.php?action=delete&sha=' . $sha . '">[X]</a><br><br>';
        echo 'Date: ' . $row['date'] . '<br><br>';
        $torrent_file = $config_upload_dir . $sha . '.torrent';
        $myfile = fopen($torrent_file, "r") or die("Unable to open file!");
        $str_file = fread($myfile, filesize($torrent_file));
        fclose($myfile);
        $r = ben_decode($str_file);
        if (is_valid_torrent($r)) {
            if (($size = get_lenght($r)) !== null) {
                echo "Size: " . get_format_size($size) . "<br><br>";
                echo "Files:<br>";
                echo get_torrent_name($r);
            } else {
                echo "Size: " . get_format_size(get_multy_lenght($r)) . "<br><br>";
                echo "Files:<br>";
                $count = get_multy_count($r);
                for ($i = 0; $i < $count; ++$i) {
                    echo get_multy_index($r, $i) . "<br>";
                }
            }
        }
    }
}