curl上传图片问题,php版本导致

php5.5及以下写法:
'imageFile' => '@'  . realpath($fileName),

php5.6及以上写法:
'imageFile' => new \CURLFile(realpath($fileName)),

最终方案:

if (class_exists('\CURLFile')) {
    $field = array('fieldname' => new \CURLFile(realpath($filepath)));
} else {
    $field = array('fieldname' => '@' . realpath($filepath));
}

猜你喜欢

转载自blog.csdn.net/weixin_38230961/article/details/110088695