Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', '1');
- function turbobit_upload($apiKey, $file, $folderId = 0)
- {
- // Get upload server
- $ch = curl_init('http://turbobit.net//v001/upload/http/server/');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, array('api_key' => $apiKey));
- $postResult = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($postResult);
- if (!$res->result) {
- print $res->message;
- return false;
- }
- // POST variables
- $postParams = array();
- foreach ($res->params as $field => $value) {
- $postParams[$field] = $value;
- }
- $postParams['folder_id'] = intval($folderId);
- if (function_exists('curl_file_create')) { // php 5.5+
- $postParams['Filedata'] = curl_file_create($file);
- } else { //
- $postParams['Filedata'] = '@' . realpath($file);
- }
- // Upload file
- $ch = curl_init($res->url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $postResult = curl_exec($ch);
- if (curl_errno($ch)) {
- print curl_error($ch);
- print "Unable to upload file.";
- return false;
- }
- curl_close($ch);
- $res = json_decode($postResult, true);
- if (!($res['result'])) {
- print "Upload error:" . $res['message'];
- return false;
- }
- // Make file links from IDs
- $links = array();
- $links['turbobit'] = "https://turbobit.net/{$res['id']}.html";
- if (isset($res['cid'])) {
- $links['hitfiles'] = "https://hitfile.net/{$res['cid']}";
- }
- return $links;
- }
- $apiKey = 'YOUR_KEY';
- // from https://turbobit.net/user/settings
- $links = turbobit_upload($apiKey, '/home/anton/tmp/download.png', 61008);
- print_r($links);
- /*
- Array
- (
- [turbobit] => https://turbobit.net/n44ukpw2fuwi.html
- [hitfiles] => https://hitfile.net/CiqXDoC
- )
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement