在使用cURL上傳圖片等文件時,利用cURL方法,傳統的上傳方法。
//圖片信息
$img_path = dirname(__FILE__).'\boy.jpg';
$img_data = array(
'media'=>'@'.$img_path
);
$res = $Wechat->uploadImg(access_token,$img_data);
var_dump($res);
此處會報錯:Deprecated: curl_setopt_array(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead……
使用CURLFile class的更正方法:
$img_path = 'C:\Users\DELL-PC\Desktop\boy.jpg';
$cfile = curl_file_create($img_path); //use the CURLFile Class 替換@的使用方法。
$img_data = array(
'media'=>$cfile
);
$res = $Wechat->uploadImg(access_token,$img_data);
var_dump($res);
這樣即可解決warning的問題!