<?php
$headers =array('Content-Type:multipart/form-data');
$data =array(
'token' => 'token',//你的token
'file'=> new \CURLFile('./1.png') //此处为图片路径
);
$data=curl('https://api.dzzui.com/v_api/imghosting_58.php','POST',$headers,$data);
echo $data;
function curl($url, $method, $headers = [], $data = null)
{
$ch = curl_init();
//执行HTTP请求时不要返回头部信息(0)
curl_setopt($ch, CURLOPT_HEADER, 0);
// 设置请求方法
if ($method === "POST") {
curl_setopt($ch, CURLOPT_POST, 1);
}
// 设置请求URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 设置请求头
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
// 设置请求体(仅适用于POST请求)
if ($data !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
// 执行请求并获取响应
$response = curl_exec($ch);
// 关闭cURL句柄
curl_close($ch);
return $response;
}
?>