curl_setopt用此函数设置上传文件请求的兼容性调整

在用curl_setopt($curl, CURLOPT_POSTFIELDS, $fileData);这个函数设置时会报错如下

curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead

查看了相关文档发现如下一段话

 

Image(5)

Image(6)

根据这个提示

得把老版本中的请求参数如

$fileData = ['media' => "@" . $filepath]; 这种写法改成

$fileData = ['media' => new \CURLFile($filepath)];

参考文档:
http://php.net/manual/zh/function.curl-setopt.php
http://stackoverflow.com/questions/18482236/fb-api-php-curl-setopt-array-the-usage-of-the-filename-api-for-file-uploadin

posted on 2016-04-18 12:51  Ryanyanglibin  阅读(583)  评论(0编辑  收藏  举报

导航