note 62380 added to function.fsockopen
| From: | Duukkis at osu1 dot php dot net | Date: | Mon, 27 Feb 2006 13:13:08 +0000 |
| Subject: | note 62380 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104483@lists.php.net to get a copy of this message | ||
Lots of tries and lots of reading http-headers...
If you want to post $_POST vars and (in this case) one file named userfile to $remote_server and
$remote_url.
<?php
// get the necessary data
$file_name = $_FILES['userfile']['name']; // the file
$tmp_name = $_FILES['userfile']['tmp_name']; // the file
$content_type = $_FILES['userfile']['type']; // the file mime type
srand((double)microtime()*1000000);
$boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
// Build the header
$header = "POST $remote_url HTTP/1.0\r\n";
$header .= "Host: $remote_server\r\n";
$header .= "Content-type: multipart/form-data, boundary=$boundary\r\n";
// attach post vars
foreach($_POST AS $index => $value){
$data .="--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=\"".$index."\"\r\n";
$data .= "\r\n".$value."\r\n";
$data .="--$boundary\r\n";
}
// and attach the file
$data .= "--$boundary\r\n";
$content_file = join("", file($tmp_name));
$data .="Content-Disposition: form-data; name=\"userfile\";
filename=\"$file_name\"\r\n";
$data .= "Content-Type: $content_type\r\n\r\n";
$data .= "".$content_file."\r\n";
$data .="--$boundary--\r\n";
$header .= "Content-length: " . strlen($data) . "\r\n\r\n";
// Open the connection
$fp = fsockopen($remote_server, 80);
// then just
fputs($fp, $header.$data);
fclose($fp);
?>
----
Server IP: 80.81.171.181
Probable Submitter: 83.145.202.161
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- http://master.php.net/note/edit/62380
Del: integrated -- http://master.php.net/note/delete/62380/integrated
Del: useless -- http://master.php.net/note/delete/62380/useless
Del: bad code -- http://master.php.net/note/delete/62380/bad+code
Del: spam -- http://master.php.net/note/delete/62380/spam
Del: non-english -- http://master.php.net/note/delete/62380/non-english
Del: in docs -- http://master.php.net/note/delete/62380/in+docs
Del: other reasons-- http://master.php.net/note/delete/62380
Reject -- http://master.php.net/note/reject/62380
Search -- http://master.php.net/manage/user-notes.php