php图片上传函数(Curl上传图片)

TANKING
English

php curl上传图片示例

<?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);
?>

Author:TANKING

阅读 1.7k

WeChat:sansure2016

4.2k 声望
232 粉丝
0 条评论

WeChat:sansure2016

4.2k 声望
232 粉丝
文章目录
宣传栏