Guest User

[php] Filejungle Upload Function

a guest
Mar 2nd, 2012
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.76 KB | None | 0 0
  1. <?php
  2. /** Author        : Halcyon aka V3g3t4
  3.  *  Website       : http://sborg.us
  4.  *  Description   : Uploader functions for FileJungle.com
  5.  *  Usage         : upFileJungle('/path/to/file/',$username,$password)
  6.  *  Returns       : Links to uploaded files
  7.  *
  8.  *  Date          : 2-Mar-2012
  9.  */
  10. ####### Account Info. ###########
  11. $ufjuser = ''; //Set you username
  12. $ufjpass = ''; //Set your password
  13. ##############################
  14.  
  15. $ufjcookie = dirname(__FILE__) . '/.fjcookie';
  16.  
  17. $filelocation = 'path/to/your.file';
  18.  
  19. uFJunLogin($ufjuser, $ufjpass, $ufjcookie);
  20. echo upFileJungle($filelocation, $ufjcookie);
  21.  
  22. function uFJunLogin($ufjuser, $ufjpass, $ufjcookie) {
  23.  
  24.     $post = array();
  25.     $post['loginUserName'] = $ufjuser;
  26.     $post['loginUserPassword'] = $ufjpass;
  27.     $post["recaptcha_response_field"] = "Login";
  28.     $post["recaptcha_challenge_field"] = "Login";
  29.     $post["recaptcha_shortencode_field"] = "Login";
  30.     $post["loginFormSubmit"] = "Login";
  31.  
  32.     $url = "http://filejungle.com/login.php";
  33.  
  34.     $page = RL_based_curl($url, $post, $ufjcookie);
  35.     is_notpresent($page, "Account Settings", "Login failed");
  36. }
  37.  
  38. function upFileJungle($filelocation, $ufjcookie) {
  39.  
  40.     $url = "http://filejungle.com/upload.php";
  41.     $ref = "http://filejungle.com/dashboard.php";
  42.     $page = RL_based_curl($url, '', $ufjcookie, $ref);
  43.     $uploadUrl = cut_str($page, "uploadUrl = '", "'");
  44.  
  45.     $ref = "http://filejungle.com";
  46.     $url = $uploadUrl . "/new?callback=jsonp" . round(microtime(true) * 1000);
  47.     $page = RL_based_curl($url, '', $ufjcookie);
  48.  
  49.     $sessionId = cut_str($page, "sessionId:'", "'");
  50.     $upurl = $uploadUrl . "/s/{$sessionId}/up";
  51.  
  52.     echo "Uploading to {$upurl}<br />";
  53.     $post = array();
  54.     $post['files'] = "@" . $filelocation;
  55.     $page = RL_based_curl($upurl, $post, $ufjcookie, $ref);
  56.  
  57.     $shortcode = cut_str($page, '"shortenCode":"', '"');
  58.     $filename = cut_str($page, '"fileName":"', '"');
  59.     $download_link = "http://www.filejungle.com/f/{$shortcode}/{$filename}";
  60.  
  61.     if ($shortcode) {
  62.         return $download_link;
  63.     } else {
  64.         echo('Error in uploading file');
  65.         return false;
  66.     }
  67. }
  68.  
  69. function is_notpresent($lpage, $mystr, $strerror, $head = 0) {
  70.     if (!stristr($lpage, $mystr)) {
  71.         echo $strerror;
  72.     }
  73. }
  74.  
  75. function cut_str($str, $left, $right) {
  76.     $str = substr(stristr($str, $left), strlen($left));
  77.     $leftLen = strlen(stristr($str, $right));
  78.     $leftLen = $leftLen ? - ($leftLen) : strlen($str);
  79.     $str = substr($str, 0, $leftLen);
  80.     return $str;
  81. }
  82.  
  83. function RL_based_curl($link, $postfields = '', $cookie = '', $refer = '', $header = 1, $follow = 1, $usragent = '') {
  84.  
  85.     $ch = curl_init($link);
  86.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  87.     if ($header)
  88.         curl_setopt($ch, CURLOPT_HEADER, 1);
  89.     else
  90.         curl_setopt($ch, CURLOPT_HEADER, 0);
  91.     if ($follow)
  92.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  93.     else
  94.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  95.     if ($usragent)
  96.         curl_setopt($ch, CURLOPT_USERAGENT, $usragent);
  97.     else
  98.         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
  99.  
  100.     if ($refer)
  101.         curl_setopt($ch, CURLOPT_REFERER, $refer);
  102.  
  103.     if ($postfields) {
  104.         curl_setopt($ch, CURLOPT_POST, 1);
  105.         curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  106.     }
  107.     if ($cookie) {
  108.         curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  109.         curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  110.     }
  111.  
  112.     $page = curl_exec($ch);
  113.  
  114.     curl_close($ch);
  115.  
  116.     if (empty($page)) {
  117.         echo "<br/>Could not connect to host: <br/> $link <br/>";
  118.         die();
  119.     } else {
  120.         return $page;
  121.     }
  122. }
  123. ?>
Advertisement
Add Comment
Please, Sign In to add comment