curl文件上传

PHP cooljun 2473℃ 0评论
function api_post($url,$data,$file_path="")
{
    $post_data =array("data" => str_replace("\\/", "/",  $data));
    if($file_path){
        //php5.5以前使用: '@'.realpath($path)
        $post_data["contractFile"] = new \CURLFile(realpath($file_path));
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, API_MAYI_SIGN_URL);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_CRLF, false);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

转载请注明:cooljun小窝 » curl文件上传

如果你觉得这篇文章对你有帮助,请支持我继续更新网站 !捐赠本站
喜欢 (0)or分享 (0)

您必须 登录 才能发表评论!