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
<?php
class rapidphp {
//////////////////////////////////////////////////////////////////
#
#
# PHP Class for uploading on Rapidshare.com
# for non-commercial use only!
#
# included: upload to free-, collector's and premium-zone, md5-check after upload
# tested under windows xp only with php 5.2.0 (should work on unix systems too, though)
#
# Check the "RapidShare AG OpenSource Perl Uploader V1.0." out, too:
# <a href=\"http://images.rapidshare.com/software/rsapi.pl\" target=\"_blank\">http://images.rapidshare.com/software/rsapi.pl</a>
#
#
#
# usage for free-users:
#
# $upload=new rapidphp;
# $upload->sendfile("myfile.rar");
#
#
# usage for premium-zone:
#
# $upload=new rapidphp;
# $upload->config("prem","username","password");
# $upload->sendfile("myfile.zip");
#
#
# usage for collector's zone:
#
# $upload=new rapidphp;
# $upload->config("col","username","password");
# $upload->sendfile("myfile.tar.gz2");
#
#
# you can upload several files if you want:
#
# $upload=new rapidphp;
# $upload->config("prem","username","password");
# $upload->sendfile("myfile.part1.rar");
# $upload->sendfile("myfile.part2.rar");
# // and so on
#
# sendfile() returns an array with data of the upload
# [0]=Download-Link
# [1]=Delete-Link
# [2]=Size of the sent file in bytes
# [3]=md5 hash (hex)
#
//////////////////////////////////////////////////////////////////
private $maxbuf=64000; // max bytes/packet
private $uploadpath="l3";
private $zone,$login,$passwort;
private function hashfile($filename) { // md5 hash of files
}
public function getserver() { // gets server for upload
$server=file_get_contents("http://rapidshare.com/cgi-bin/rsapi.cgi?sub=nextuploadserver_v1"); }
return sprintf("rs%s%s.rapidshare.com",$server,$this->uploadpath); }
public function config($zone,$login="",$passwort="") { // configuration
$this->zone=$zone;
$this->login=$login;
$this->passwort=$passwort;
}
public function sendfile($file) { // upload a file
$this->zone="free";
}
if($this->zone=="prem" OR $this->zone=="col") {
if(empty($this->login) OR
empty($this->passwort)) { $this->zone="free";
}
}
}
$hash=$this->hashfile($file); // hash of the file
$size=filesize($file); // filesize (bytes) of the file $cursize=0; // later needed
$server=$this->getserver(); // get server for uploading
print "Using $server:80\n"; $sock= fsockopen($server,80
,$errorno,$errormsg,30
) or
die("Unable to open connection to rapidshare\nError $errorno ($errormsg)"); $boundary = "---------------------632865735RS4EVER5675865";
$contentheader="r\nContent-Disposition: form-data; name=\"rsapi_v1\"r\nr\n1r\n";
if($this->zone=="prem") { // premium
$contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"login\"r\nr\n%sr\n",$boundary,$this->login); $contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"password\"r\nr\n%sr\n",$boundary,$this->passwort); print "Upload as a Premium-User\n"; }
if($this->zone=="col") { // collector
$contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"freeaccountid\"r\nr\n%sr\n",$boundary,$this->login); $contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"password\"r\nr\n%sr\n",$boundary,$this->passwort); print "Upload as a Collector\n"; }
$contentheader .= sprintf("%sr\nContent-Disposition: form-data; name=\"filecontent\"; filename=\"%s\"r\nr\n",$boundary,$file); $contenttail = "r\n".$boundary."--r\n";
$contentlength = strlen($contentheader) + $size + strlen($contenttail); $header = "POST /cgi-bin/upload.cgi HTTP/1.0r\nContent-Type: multipart/form-data; boundary=".$boundary."r\nContent-Length: ".$contentlength."r\nr\n";
fwrite($sock,$header.$contentheader); // ok: now we have sent everything except the file!
while($cursize < $size) { // If we didn't upload everything, repeat!
$buf=fread($fp,$this->maxbuf) or
die("Unable to read file"); // read max bytes from the file $cursize=$cursize+strlen($buf); if(fwrite($sock,$buf)) { // send data printf("%d of %d Bytes sent.\n",$cursize,$size); }
}
fwrite($sock,$contenttail); // finished printf("All %d bytes sent to the server!\n",$size); $ret=fread($sock,10000
); // receive data (links, hash, bytes) preg_match("/r\nr\n(.+)/s",$ret,$match); // we don't need the http-header $ret=explode("\n",$match[1
]); // every line gets an entry in an array foreach($ret as $id => $cont) {
if($id!=0) { // very boring stuff!
if($id>4) break; // break foreach
$key_val[]=substr($cont,8
); // throw away the first eight chars }
}
if($hash==$key_val[3]) { // if the hash is == hash of the local file
return $key_val;
} else { // omg! upload failed!
printf("Upload FAILED! Your hash is %s, while the uploaded file has the hash %s",$hash,$key_val[3
]); return FALSE;
}
}
}
?>
Ten post edytował bartek24m 9.02.2009, 11:51:48