Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] wysylanie plików na rapidshare z poziomu http
bartek24m
post 9.02.2009, 11:24:06
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 17.06.2006

Ostrzeżenie: (0%)
-----


Chiałbym wysylać pliki za pomocą formularza z serwera na rapidshare przez konto premium

znalazłem taki kod ktory jest przetlumaczony na php z perl

jest to tylko class
nie bardzo wiem jak mam polączyć to z formularzem w ktorym zaznaczam checboxem nazwe pliku i klikam prześlij do filename

  1. <?php
  2.  
  3. class rapidphp {
  4.  
  5.  
  6. //////////////////////////////////////////////////////////////////
  7. #
  8. #
  9. #   PHP Class for uploading on Rapidshare.com
  10. #   for non-commercial use only!
  11. #
  12. #   included: upload to free-, collector's and premium-zone, md5-check after upload
  13. #   tested under windows xp only with php 5.2.0 (should work on unix systems too, though)
  14. #
  15. #   Check the "RapidShare AG OpenSource Perl Uploader V1.0." out, too:
  16. #   <a href=\"http://images.rapidshare.com/software/rsapi.pl\" target=\"_blank\">http://images.rapidshare.com/software/rsapi.pl</a>
  17. #
  18. #
  19. #
  20. #   usage for free-users:
  21. #
  22. #     $upload=new rapidphp;
  23. #     $upload->sendfile("myfile.rar");
  24. #
  25. #
  26. #   usage for premium-zone:
  27. #
  28. #     $upload=new rapidphp;
  29. #     $upload->config("prem","username","password");
  30. #     $upload->sendfile("myfile.zip");
  31. #
  32. #
  33. #   usage for collector's zone:
  34. #
  35. #     $upload=new rapidphp;
  36. #     $upload->config("col","username","password");
  37. #     $upload->sendfile("myfile.tar.gz2");
  38. #
  39. #
  40. #   you can upload several files if you want:
  41. #
  42. #     $upload=new rapidphp;
  43. #     $upload->config("prem","username","password");
  44. #     $upload->sendfile("myfile.part1.rar");
  45. #     $upload->sendfile("myfile.part2.rar");
  46. #     // and so on
  47. #
  48. #   sendfile() returns an array with data of the upload
  49. #    [0]=Download-Link
  50. #    [1]=Delete-Link
  51. #    [2]=Size of the sent file in bytes
  52. #    [3]=md5 hash (hex)
  53. #
  54. //////////////////////////////////////////////////////////////////
  55.  
  56.         private $maxbuf=64000; // max bytes/packet
  57.         private $uploadpath="l3";
  58.         private $zone,$login,$passwort;
  59.  
  60.         private function hashfile($filename) { // md5 hash of files
  61.             return strtoupper(md5_file($filename));
  62.         }
  63.         public function getserver() { // gets server for upload
  64.             while(empty($server)) {
  65.                  $server=file_get_contents("http://rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver_v1");
  66.          }
  67.                 return sprintf("rs%s%s.rapidshare.com",$server,$this->uploadpath);
  68.         }
  69.         public function config($zone,$login="",$passwort="") { // configuration
  70.             $this->zone=$zone;
  71.                 $this->login=$login;
  72.                 $this->passwort=$passwort;
  73.         }
  74.         public function sendfile($file) { // upload a file
  75.             if(empty($this->zone)) {
  76.                     $this->zone="free";
  77.                 }
  78.                 if($this->zone=="prem" OR $this->zone=="col") {
  79.                     if(empty($this->login) OR empty($this->passwort)) {
  80.                             $this->zone="free";
  81.                         }
  82.                 }
  83.                 if(!file_exists($file)) {
  84.                     die("File not found!");
  85.                 }
  86.                 $hash=$this->hashfile($file); // hash of the file
  87.                 $size=filesize($file); // filesize (bytes) of the file
  88.                 $cursize=0; // later needed
  89.                 $server=$this->getserver(); // get server for uploading
  90.                 print "Using $server:80\n";
  91.              $sock=    fsockopen($server,80,$errorno,$errormsg,30) or die("Unable to open connection to rapidshare\nError $errorno ($errormsg)");
  92.        stream_set_timeout($sock,3600); // anti timeout
  93.                 $fp=    fopen($file,"r");
  94.                 $boundary = "---------------------632865735RS4EVER5675865";
  95.                 $contentheader="r\nContent-Disposition: form-data; name=\"rsapi_v1\"r\nr\n1r\n";
  96.                 if($this->zone=="prem") {  // premium
  97.              $contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"login\"r\nr\n%sr\n",$boundary,$this->login);
  98.              $contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"password\"r\nr\n%sr\n",$boundary,$this->passwort);
  99.                           print "Upload as a Premium-User\n";
  100.                 }
  101.                 if($this->zone=="col") { // collector
  102.              $contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"freeaccountid\"r\nr\n%sr\n",$boundary,$this->login);
  103.              $contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"password\"r\nr\n%sr\n",$boundary,$this->passwort);
  104.                           print "Upload as a Collector\n";
  105.                 }
  106.                 $contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"filecontent\"; filename=\"%s\"r\nr\n",$boundary,$file);
  107.        $contenttail = "r\n".$boundary."--r\n";
  108.        $contentlength = strlen($contentheader) + $size + strlen($contenttail);
  109.                 $header = "POST /cgi-bin/upload.cgi HTTP/1.0r\nContent-Type: multipart/form-data; boundary=".$boundary."r\nContent-Length: ".$contentlength."r\nr\n";
  110.                 fwrite($sock,$header.$contentheader);
  111.                 // ok: now we have sent everything except the file!
  112.                 while($cursize < $size) { // If we didn't upload everything, repeat!
  113.                     $buf=fread($fp,$this->maxbuf) or die("Unable to read file"); // read max bytes from the file
  114.                         $cursize=$cursize+strlen($buf);
  115.                         if(fwrite($sock,$buf)) { // send data
  116.                             printf("%d of %d Bytes sent.\n",$cursize,$size);
  117.                         }
  118.                 }
  119.                 fwrite($sock,$contenttail); // finished
  120.                 printf("All %d bytes sent to the server!\n",$size);
  121.                 $ret=fread($sock,10000); // receive data (links, hash, bytes)
  122.                 preg_match("/r\nr\n(.+)/s",$ret,$match); // we don't need the http-header
  123.          $ret=explode("\n",$match[1]); // every line gets an entry in an array
  124.         fclose($sock);
  125.         fclose($fp);
  126.                 foreach($ret as $id => $cont) {
  127.                     if($id!=0) { // very boring stuff!
  128.                             if($id>4) break; // break foreach
  129.                             $key_val[]=substr($cont,8); // throw away the first eight chars
  130.                         }
  131.                 }
  132.                 if($hash==$key_val[3]) { // if the hash is == hash of the local file
  133.                  return $key_val;
  134.                 } else {  // omg! upload failed!
  135.                     printf("Upload FAILED! Your hash is %s, while the uploaded file has the hash %s",$hash,$key_val[3]);
  136.                         return FALSE;
  137.                 }
  138.         }
  139. }
  140.  
  141. ?>


Ten post edytował bartek24m 9.02.2009, 11:51:48
Go to the top of the page
+Quote Post
marcinpruciak
post 9.02.2009, 16:10:42
Post #2





Grupa: Zarejestrowani
Postów: 161
Pomógł: 9
Dołączył: 14.07.2008

Ostrzeżenie: (0%)
-----


Wszystko masz opisane w komentarzu:

  1. <?php
  2. #   usage for premium-zone:
  3. $upload=new rapidphp;
  4. $upload->config("prem","username","password");
  5. $upload->sendfile("myfile.zip");
  6. ?>



Jeśli chcesz wysyłać kilka plików, zrób sobię pętlę.

Ten post edytował marcinpruciak 9.02.2009, 16:11:46


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 6.07.2025 - 19:06