<?php
$boundary = '-----------------------------168279961491';
// our request body
$str = "$boundary\r\nContent-Disposition: form-data; name='how_do_i_turn_you'\r\n\r\non\r\n$boundary--\r\n";
// set up cURL
$ch=curl_init('http://example.com/');
curl_setopt_array($ch, array(
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array( // we need to send these two headers
'Content-Type: multipart/form-data; boundary='.$boundary,
'Content-Length: '.strlen($str)
),
// note, do not set the CURLOPT_POSTFIELDS setting
CURLOPT_READFUNCTION => 'myfunc'
));
// function to stream data
// I'm not sure what the file pointer $fp does in this context
// but $ch is the cURL resource handle, and $len is how many bytes to read
function myfunc($ch, $fp, $len) {
static $pos=0; // keep track of position
global $str;
// set data
$data = substr($str, $pos, $len);
// increment $pos
$pos += strlen($data);
// return the data to send in the request
return $data;
}
// execute request, and show output for lolz
echo curl_exec($ch);
curl_close($ch);
http://zingaburga.com/2011/02/streaming-post-data-through-php-curl-using-curlopt_readfunction/