djtozz Posted September 29, 2009 Share Posted September 29, 2009 Hello, I have a working script which can upload a file to megaupload using curl. Now I would like to do a remote login, before the script uploads the file (This way the file is stored under my account , and not uploaded as guest) So basicly I have 2 working peaces of code (the login and the file upload) and I just want to integrate them into one code, I simply don't know where to paste the login code. Working Login Script: $query = "login=1&redir=1&username=MY_USERNAME&password=MY_PASSWORD"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://www.megaupload.com/"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); Working Upload script: $done = 0; $flag = 0; $file_loc = 'uploads/' . $info['name']; $url = 'http://megaupload.com'; $file = @file ($url); $count = count ($file); $i = '0'; while ($i < $count) { if (strstr ($file[$i], 'megaupload.com/upload_done.php')) { $main = $file[$i]; $flag = 1; break; } ++$i; } if ($flag == 1) { $parse = explode ('action="', $main); $parse1 = explode ('" ', $parse[1]); $posturl = $parse1[0]; $parse2 = explode ('UPLOAD_IDENTIFIER=', $posturl); $mega_uid = $parse2[1]; $postcontent = array (); $postcontent['file'] = '@' . $file_loc; $postcontent['UPLOAD_IDENTIFIER'] = $mega_uid; $postcontent['sessionid'] = $mega_uid; $postcontent['message'] = ''; $ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, $posturl); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postcontent); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($ch); curl_close ($ch); $flag = 0; $file = explode (' ', $result); $count = count ($file); $i = '0'; while ($i < $count) { if ((strstr ($file[$i], 'megaupload.com') AND strstr ($file[$i], '?d='))) { $main = $file[$i]; $flag = 1; break; } ++$i; } $done = 0; if ($flag == 1) { $parse = explode ('?d=', $main); $parse1 = explode ('\';', $parse[1]); $url = 'http://www.megaupload.com/?d=' . $parse1[0]; $done = 1; } } Any help would be apriciated! Link to comment https://forums.phpfreaks.com/topic/175919-curl-remote-login-script/ Share on other sites More sharing options...
poofried Posted September 29, 2009 Share Posted September 29, 2009 make a class/function? Link to comment https://forums.phpfreaks.com/topic/175919-curl-remote-login-script/#findComment-927050 Share on other sites More sharing options...
djtozz Posted September 29, 2009 Author Share Posted September 29, 2009 make a class/function? Thanks for your reaction, my excuses, I'm very N00B in this. So I'm not sure how to start. Link to comment https://forums.phpfreaks.com/topic/175919-curl-remote-login-script/#findComment-927076 Share on other sites More sharing options...
djtozz Posted October 5, 2009 Author Share Posted October 5, 2009 Anybody please? Thanks Link to comment https://forums.phpfreaks.com/topic/175919-curl-remote-login-script/#findComment-930680 Share on other sites More sharing options...
aciidb0mb3r Posted October 5, 2009 Share Posted October 5, 2009 $ran=rand(1,1000); $cookie = 'uploader'.$ran.'.txt'; $query = "login=1&redir=1&username=MY_USERNAME&password=MY_PASSWORD"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://www.megaupload.com/"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); $data = curl_exec($ch); curl_close($ch); $done = 0; $flag = 0; $file_loc = 'uploads/' . $info['name']; $url = 'http://megaupload.com'; $file = @file ($url); $count = count ($file); $i = '0'; while ($i < $count) { if (strstr ($file[$i], 'megaupload.com/upload_done.php')) { $main = $file[$i]; $flag = 1; break; } ++$i; } if ($flag == 1) { $parse = explode ('action="', $main); $parse1 = explode ('" ', $parse[1]); $posturl = $parse1[0]; $parse2 = explode ('UPLOAD_IDENTIFIER=', $posturl); $mega_uid = $parse2[1]; $postcontent = array (); $postcontent['file'] = '@' . $file_loc; $postcontent['UPLOAD_IDENTIFIER'] = $mega_uid; $postcontent['sessionid'] = $mega_uid; $postcontent['message'] = ''; $ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, $posturl); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postcontent); curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($ch); curl_close ($ch); $flag = 0; $file = explode (' ', $result); $count = count ($file); $i = '0'; while ($i < $count) { if ((strstr ($file[$i], 'megaupload.com') AND strstr ($file[$i], '?d='))) { $main = $file[$i]; $flag = 1; break; } ++$i; } $done = 0; if ($flag == 1) { $parse = explode ('?d=', $main); $parse1 = explode ('\';', $parse[1]); $url = 'http://www.megaupload.com/?d=' . $parse1[0]; $done = 1; } } This should do it. Link to comment https://forums.phpfreaks.com/topic/175919-curl-remote-login-script/#findComment-930722 Share on other sites More sharing options...
aciidb0mb3r Posted October 5, 2009 Share Posted October 5, 2009 unlink('uploader'.$ran.'.txt'); also add this to last so that it removes the cookie file after upload and make sure the folder you put the script in is CHMOD 777 Link to comment https://forums.phpfreaks.com/topic/175919-curl-remote-login-script/#findComment-930725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.