note 85155 modified in function.fsockopen by felipe

From: Date: Tue, 19 Aug 2008 01:43:20 +0000
Subject: note 85155 modified in function.fsockopen by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143617@lists.php.net to get a copy of this message
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); ?> --was-- Sending multiple files with form(modification of sir_reality2001 at yahoo dot com's and Duukkis's scripts): $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); http://php.net/manual/en/function.fsockopen.php

« previous php.notes (#143617) next »