php版本7.2 用curl往uploadTempMedia接口上传图片,百度上说要用php5.6+要用new CURLfile ,可是new了照样报错
public function get_img_media_id()
{
$image = ROOT_PATH.'public/static/card/yind.png';
$send_data = [
'type'=>'image',
'media'=>$image
];
$ret = mycurl_post_file($this ->get_img_media_id_url,$send_data);
return $ret;
}
function mycurl_post_file($url,$file)
{
$ch = curl_init();
$file['media'] = new CURLFile(realpath($file['media']));
$file = json_encode($file);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//流的形势不直接输出
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1); //设置是通过post还是get方法
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);//不检查证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);//不检查证书名
curl_setopt($ch, CURLOPT_POSTFIELDS, $file);
curl_setopt(
$ch,CURLOPT_HTTPHEADER,
array(
'Content-Type: application/josn'
)
);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
求大佬指点 感激不尽
文件类型 header不能设置为json 。。。。。。。 o_o