Witam mam skrypt u siebie na serwerze który odpowiada za wysylanie plików na rapidshare
skrypt działa tak ...
zaznaczam plik do wyslania i klikam w formularzu submit aby mogl odpalić się skrypt do uploadowania plików
<?php
<input type="submit" target="_blank" name="upload1" style="FONT-SIZE: 10px;border:1px solid #000000;" title="Zaznacz Pliki i kliknij ten przycisk aby wgrać na serwer rapidshare.com !" value="+ Upload na Rapidshare" />
?>
<?php
if(isset($_POST['upload1'])){ $c=count($_POST['zaznacz']); //echo $c;
echo ('<center>Pomyślnie zostały wgrane pliki poniżej linki do tych plików !<BR><form><TEXTAREA style="FONT-SIZE: 11px;border:1px dashed #FF00FF;" rows="8" cols="90" name="pole">'); for ($x=1; $x<$c+1; $x++)
{
//echo $_POST['zaznacz'][$x-1];
$upload_file = $_POST['zaznacz'][$x-1];
$upload=new rapidphp;
$upload->config("prem","login","pass");
$wynik=$upload->sendfile("$upload_file");
}
echo ('</TEXTAREA></form></center>'); }
?>
oczywiście wszystko działa dzięki tej klasie
<?php
class rapidphp {
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
$sock= fsockopen($server,80
,$errorno,$errormsg,30
) or
die("Unable to open connection to rapidshare\nError $errorno ($errormsg)"); $boundary = "---------------------632865735RS4EVER5675864";
$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); }
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); }
$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); 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 }
}
fwrite($sock,$contenttail); // finished $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;
}
}
}
?>
Jak zrobić aby po kliknięciu w formularz wyślij pojawila sie informacja z ajaxem z jaką prędkością uploaduje pliki
+ ile już % już uploadowało
obecnie wygląda to tak ze klikam na submit i czekam kilka chwil az wszystko się wyśle i wyświetli wynik
załóżmy że jestem wstanie wyciągnąć informacje o wielkości pliku, problem w tym ze nie wiem jak live wyświetlić z jaka prędkością są uploadowane pliki
czy jest ktoś kto mógłby mnie naprowadzić aby uzyskac tego typu informacje
Ten post edytował bartek24m 16.03.2009, 15:06:02