note 39868 added to function.fsockopen

From: Date: Fri, 13 Feb 2004 14:45:00 +0000
Subject: note 39868 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-65097@lists.php.net to get a copy of this message
<? // This is a modification to the script I submitted below. // This script is an example of posting multiple files using // fsockopen. // The tricky part is making sure the HTTP headers and file boundaries are acceptable to the target webserver. // This script is for example purposes only and could/should be improved upon. $host='targethost'; $port=80; $path='/test/socket/file_upload/receive_files.php'; // the file you want to upload $file_array[0] = "dingoboy.gif"; // the file $file_array[1] = "dingoboy2.gif"; // the file $file_array[2] = "dingoboy3.gif"; // the file $content_type = "image/gif"; // the file mime type //$content_type = "text/plain"; //echo "file_array[0]:$file_array[0]<br><br>"; srand((double)microtime()*1000000); $boundary = "---------------------------".substr(md5(rand(0,32000)),0,10); $data = "--$boundary"; for($i=0;$i<count($file_array);$i++){ $content_file = join("", file($file_array[$i])); $data.=" Content-Disposition: form-data; name=\"file".($i+1)."\"; filename=\"$file_array[$i]\" Content-Type: $content_type $content_file --$boundary"; } $data.="--\r\n\r\n"; $msg = "POST $path 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); fputs($f,$msg.$data); // get the response while (!feof($f)) $result .= fread($f,32000); fclose($f); ?> ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39868 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39868&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39868&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65097) next »