关于php:php图片上传函数Curl上传图片

71次阅读

共计 661 个字符,预计需要花费 2 分钟才能阅读完成。

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

正文完
 0