<?php
header("Content-type:application/json");
function uploadimg($url,$data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers[] = "user-agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3947.100 Safari/537.36";
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
return curl_exec($ch);
curl_close($ch);
}
// 调用函数
$data = array(
'上传参数' => new CURLFile(realpath('test.jpg')),
);
echo uploadimg('上传接口URL',$data);
?>
|