home *** CD-ROM | disk | FTP | other *** search
- <?
- # This software may be used and distributed according to the terms
- # of the GNU Public License, incorporated herein by reference.
- #
- # See file COPYING for details of the GNU GPL.
- #
- #################################
- #WebNap Client copyright 2000
- #Aakash Kambuj - aakash@idearing.com
- #Kalpak Kothari - kalpak@idearing.com
- #################################
- #
- #You are welcome to modify and distribute this code, but you MUST retain
- #this copyright notice above any notices you put. If you use this program
- #beyond personal use, we request that you send us a copy of your modified code.
- #
- #Napster is a registered trademark of Napster Inc - http://www.napster.com
- #
-
- function download($username,$rhost,$rport,$title,$filename) {
- global $QUERY_STRING;
-
- $MTU = 2048;
- $title = rawurldecode($title);
- $filename = rawurldecode($filename);
-
- // if using HTTP_GET, we also need to un-quote the strings
- if ($QUERY_STRING != "") {
- $title = stripslashes($title);
- $filename = stripslashes($filename);
- }
-
- $remote_user = fsockopen($rhost, $rport, &$errstr, &$errno); //open a connection to the remote user
- if (!$remote_user){
- echo "ERROR $errstr ($errno)<br>\n";
- return;
- }
-
- //read magic character '1'
- $dt = (string)fread($remote_user, 1);
- if ($dt != "1") {
- print( "<br>ERROR Expected magic character '1' from remote user: $dt");
- return;
- }
-
- fwrite($remote_user, "GET"); // write string "GET"
- flush();
- //send file name to get
- $mess = "$username " . $title . " 0";
- // echo "String sent to remote client after \"GET\": $mess <br>";
- fwrite($remote_user, $mess);
-
-
-
-
- //read the size of the mp3 file
- $file_length = "";
- $temp=0;
- for ($i=0;$i<$MTU;$i++){
-
- $temp = fread($remote_user,1);
- if ($temp< '0' || $temp> '9'){
- break;
- }
- $file_length .= $temp;
- }
-
- $mpsize = (int)$file_length;
- settype($mpsize,"integer");
- flush();
-
-
- if ($mpsize <= 0) {
- echo "<br>ERROR. Remote user sent an invalid filesize: $mpsize";
- fclose($remote_user);
- exit;
- }
-
- $num = pack( "C",$temp);
-
- // start sending file. indicate browser to download.
- header( "Content-type: application/octet-stream" );
- header( "Content-Disposition: attachment; filename=$filename" );
- header( "Content-Length: $mpsize" );
-
- echo $num; //first byte of mp3 file
-
- $count=1;
- do {
- $received = fread($remote_user, $MTU);
- $count +=$MTU;
- echo $received;
- } while ($count<$mpsize);
- fclose($remote_user);
- exit;
- }
-
- download($username,$rhost,$rport,$title,$filename);
-
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-