note 85155 deleted from function.fsockopen by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 01:47:09 +0000 |
| Subject: | note 85155 deleted from function.fsockopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155596@lists.php.net to get a copy of this message | ||
Note Submitter: kj83 at op dot pl
----
Sending multiple files with form(modification of sir_reality2001 at yahoo dot com's and
Duukkis's scripts):
<?php
$boundary = "AaB03x";
$boundary2 = "BbC04y";
// Build the header
$header = "POST remoteurl HTTP/1.0\r\n";
$header .= "Host: remotehost\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
for ($i=0; $i<count($_FILES['userfile']['name']);$i++)
{
$data .= "--$boundary\r\n";
if ($_FILES['userfile']['name'][$i] != '')
{
$content_file = join("",
file($_FILES['userfile']['tmp_name'][$i]));
$data.="Content-Disposition: file; name=\"userfile[$i]\";
filename=\"".$_FILES['userfile']['name'][$i]."\"\r\n";
$data .= "Content-Type:
".$_FILES['userfile']['type'][$i]."\r\n\r\n";
$data .= "".$content_file."\r\n";
$data .="--$boundary\r\n";
}
}
$data .="--$boundary--\r\n";
$header .= "Content-length: " . strlen($data) . "\r\n\r\n";
$fp = fsockopen($remote_server, 80);
?>