/**
* post請求上傳文件
* @param $url
* @param $post_data
* @return bool|string
*/
function curl_post($url,$post_data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$url是上傳地址
$post_data是上傳的參數
$post_data = [
'name' => 'xxxx',
'file' => new \CURLFile('絕對路徑'), //文件中使用別的路徑沒有辦法上傳成功,只有絕對路徑成功,具體原因不明
];