コード例 #1
0
<?php

$verifyToken = md5('unique_salt' . $_POST['timestamp']);
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    // Validate the file type
    $fileTypes = array('torrent');
    $fileParts = pathinfo($_FILES['Filedata']['name']);
    if (in_array($fileParts['extension'], $fileTypes)) {
        require 'lightbenc.php';
        $info = Lightbenc::bdecode_getinfo($tempFile);
        if (isset($info['info_hash'])) {
            success($info['info_hash']);
        } else {
            failed();
        }
    } else {
        failed();
    }
}
function success($info_hash)
{
    $result = array('result' => 1, 'url' => 'magnet:?xt=urn:btih:' . strtoupper($info_hash));
    $json = json_encode($result);
    if ($json) {
        echo $json;
    }
}
function failed()
{
    $result = array('result' => 0, 'url' => null);
コード例 #2
0
 public static function bdecode_getinfo($filename)
 {
     $t = Lightbenc::bdecode(file_get_contents($filename, FILE_BINARY));
     $t['info_hash'] = sha1(Lightbenc::bencode($t['info']));
     if (isset($t['info']['files']) && is_array($t['info']['files'])) {
         //multifile
         $t['info']['size'] = 0;
         $t['info']['filecount'] = 0;
         foreach ($t['info']['files'] as $file) {
             $t['info']['filecount']++;
             $t['info']['size'] += $file['length'];
         }
     } else {
         $t['info']['size'] = $t['info']['length'];
         $t['info']["filecount"] = 1;
         $t['info']['files'][0]['path'] = $t['info']['name'];
         $t['info']['files'][0]['length'] = $t['info']['length'];
     }
     return $t;
 }
コード例 #3
0
<?php

$url = urldecode($_GET['magnet']);
$torrent = getUrl($url, '', 'test');
echo "<pre>";
var_dump($torrent);
die;
require 'lightbenc.php';
$info = Lightbenc::bdecode_getinfo($torrent);
echo "<pre>";
var_dump($info);
die;
curl_close($ch);
if ($magnet = generateMagnet($info)) {
    success($magnet);
} else {
    failed();
}
function getUrl($url, $save_dir = '', $filename = '', $type = 0)
{
    if (trim($url) == '') {
        return array('file_name' => '', 'save_path' => '', 'error' => 1);
    }
    if (trim($save_dir) == '') {
        $save_dir = './';
    }
    if (trim($filename) == '') {
        //保存文件名
        $ext = strrchr($url, '.');
        if ($ext != '.gif' && $ext != '.jpg') {
            return array('file_name' => '', 'save_path' => '', 'error' => 3);