note 39443 deleted from function.fsockopen by vincent

From: Date: Fri, 13 Feb 2004 14:59:54 +0000
Subject: note 39443 deleted from function.fsockopen by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65100@lists.php.net to get a copy of this message
Note Submitter: sir_reality2001@yahoo.com ---- <? //To emulate a form file upload. //Note that this is a combination of other scripts found on several user groups that were incomplete. Of course this for example only and could be improved upon. //To upload a file manually using fsockopen : $host='yourhost'; $port=80; // the URL of the receiver of file $remote_page = "http://theTargetHost/receive_files.php"; // the file you want to send $file = "text.txt"; // the file srand((double)microtime()*1000000); $content_type = "text/plain"; $content_file = join("", file($file)); $boundary = "---------------------------".substr(md5(rand(0,32000)),0,10); $data = "--$boundary Content-Disposition: form-data; name=\"file1\"; filename=\"$file\" Content-Type: $content_type $content_file"."--$boundary--\r\n\r\n"; $msg = "POST $remote_page HTTP/1.0 Content-Type: multipart/form-data; boundary=$boundary Content-Length: ".strlen($data)."\r\n\r\n"; $result=""; // open the connection $f = fsockopen($host, $port); //post the data fputs($f,$msg.$data); //get the response while (!feof($f)) $result .= fread($f,32000); fclose($f); print $result; ?>

« previous php.notes (#65100) next »