Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.07 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. error_reporting(E_ALL);
  5. ini_set('display_errors', '1');
  6.  
  7.  
  8. function turbobit_upload($apiKey, $file, $folderId = 0)
  9. {
  10.     // Get upload server
  11.     $ch = curl_init('http://turbobit.net//v001/upload/http/server/');
  12.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  13.     curl_setopt($ch, CURLOPT_POST, 1);
  14.     curl_setopt($ch, CURLOPT_POSTFIELDS, array('api_key' => $apiKey));
  15.     $postResult = curl_exec($ch);
  16.     curl_close($ch);
  17.     $res = json_decode($postResult);
  18.     if (!$res->result) {
  19.         print $res->message;
  20.         return false;
  21.     }
  22.  
  23.     // POST variables
  24.     $postParams = array();
  25.     foreach ($res->params as $field => $value) {
  26.         $postParams[$field] = $value;
  27.     }
  28.     $postParams['folder_id'] = intval($folderId);
  29.     if (function_exists('curl_file_create')) { // php 5.5+
  30.         $postParams['Filedata'] = curl_file_create($file);
  31.     } else { //
  32.         $postParams['Filedata'] = '@' . realpath($file);
  33.     }
  34.  
  35.     // Upload file
  36.     $ch = curl_init($res->url);
  37.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  38.     curl_setopt($ch, CURLOPT_POST, 1);
  39.     curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
  40.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  41.     $postResult = curl_exec($ch);
  42.     if (curl_errno($ch)) {
  43.         print curl_error($ch);
  44.         print "Unable to upload file.";
  45.        return false;
  46.     }
  47.     curl_close($ch);
  48.     $res = json_decode($postResult, true);
  49.     if (!($res['result'])) {
  50.         print "Upload error:" . $res['message'];
  51.         return false;
  52.     }
  53.  
  54.     // Make file links from IDs
  55.     $links = array();
  56.     $links['turbobit'] = "https://turbobit.net/{$res['id']}.html";
  57.     if (isset($res['cid'])) {
  58.         $links['hitfiles'] = "https://hitfile.net/{$res['cid']}";
  59.     }
  60.     return $links;
  61. }
  62.  
  63. $apiKey = 'YOUR_KEY';
  64. // from https://turbobit.net/user/settings
  65. $links = turbobit_upload($apiKey, '/home/anton/tmp/download.png', 61008);
  66. print_r($links);
  67. /*
  68.  
  69.  
  70.  Array
  71. (
  72.     [turbobit] => https://turbobit.net/n44ukpw2fuwi.html
  73.     [hitfiles] => https://hitfile.net/CiqXDoC
  74. )
  75.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement