/**
* 文件上传接口
* @params images/6/2020/09/IBGzEkle18FfnaZBPGwfUzpDncM651qAVCap_jSI75V8g2mdyNYnbvSswI011XeB.jpg 文件的相对路径
* @return mixed
*/
public function upload($img = "")
{
//带上授权token
$header[] = "Authorization:Bearer " . $this->getToken();
$url = $this->apiUrl.'/api/owner/upload';
$header[] = "Content-Type:multipart/form-data;";//header一定要带上
$imgTmp = explode("/", $img);
$countTmp = count($imgTmp);
#注意CURLFile参数:$filename 本地文件的位置,$mimetype文件类型,$postname传过去图片的名称
$post_data = array(
'file'=>new CURLFile(ATTACHMENT_ROOT.$img,'image/jpg',$imgTmp[$countTmp-1])
);
$ch = curl_init();
curl_setopt($ch , CURLOPT_URL , $url);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch , CURLOPT_POST, 1);
curl_setopt($ch , CURLOPT_POSTFIELDS, $post_data);
// curl_setopt($ch , CURLOPT_BINARYTRANSFER, true); //raw 格式输出
curl_setopt($ch , CURLOPT_HTTPHEADER, $header);
curl_setopt($ch , CURLOPT_HEADER, false); // 不返回头信息
$output = curl_exec($ch);
if (!$output = curl_exec($ch)) {
# trigger_error(curl_error($ch));
// pdo_insert('log', ['name'=>'curl_get:error','log'=>json_encode(curl_error($ch)),'time'=>date('Y-m-d H:i:s',time())]);
}
curl_close($ch);
return $output;
}