note 39443 added to function.fsockopen
| From: | sir_reality2001 at yahoo dot com | Date: | Wed, 28 Jan 2004 20:44:52 +0000 |
| Subject: | note 39443 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64339@lists.php.net to get a copy of this message | ||
<?
//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;
?>
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39443
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39443&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39443&report=yes
Search -- http://master.php.net/manage/user-notes.php