<?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);
<?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);