2019 unicorn companies pay a lot of money to recruit Python engineers>>>
<?php$boundary = '------------------- ---------168279961491';
// our request body
$str = "$boundary\r\nContent-Disposition: form-data; name=& #39;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 => 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= 39;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 positionglobal $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);
Streaming POST data through PHP cURL Using CURLOPT_READFUNCTION
Transfer: https://my.oschina.net/swingcoder/blog/896846