hot3.png

Another way for PHP to use curl to transfer files

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 readfunction 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 lolzecho curl_exec($ch) ;curl_close($ch); Streaming POST data through PHP cURL Using CURLOPT_READFUNCTION Transfer: https://my.oschina.net/swingcoder/blog/896846

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索