//模拟from表单提交
function form_post($url,$param) {
$delimiter = uniqid();
$post_data = buildData($param,$delimiter);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Content-Type: multipart/form-data; boundary=" . $delimiter,
"Content-Length: " . strlen($post_data)
]);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
//编译请求头格式和数据流
function buildData($param,$delimiter){
$data = '';
$eol = "\r\n";
foreach ($param as $name => $content) {
$data .= "--" . $delimiter . "\r\n". 'Content-Disposition: form-data; name="' . $name . "\"\r\n\r\n". $content . "\r\n";
}
$data .= "--" . $delimiter . $eol. 'Content-Disposition: form-data; name="media"; "' . "\r\n". 'Content-Type:application/octet-stream'."\r\n\r\n";
$data .= "--" . $delimiter . "--\r\n";
return $data;
}
06-14
1567
06-05
4623
04-25
430
02-18
740