上传各类media,一直显示文件丢失的错误'{"errcode":41005,"errmsg":"media data missing"}'。但是文件确定在该路径下面,代码应该也是没有错误的啊。是什么问题呢?大家有没有遇到过呢?
public function uploadMedia($aksk) { $type = "image"; $filepath = '@D:\workspace\appidaib9fc427f\angang.jpg'; $filedata = array ( "media" =>$filepath ); $url = 'http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token='.$aksk.'&type='.$type; $result=$this->https_request($url,$filedata); return $result; } public function https_request($url, $data = null) { $curl = curl_init (); curl_setopt ( $curl, CURLOPT_URL, $url ); curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, FALSE ); if (! empty ( $data )) { curl_setopt ( $curl, CURLOPT_POST, 1 ); curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data ); } curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 ); $output = curl_exec ( $curl ); curl_close ( $curl ); return $output; }
参考 https://github.com/baoshan/wx/issues/6 :
Wechat server expect the form-data part ended with a
\r\n
butnode-request
orform-data
didn't do the trick so the code above will certainly failed. However, if I added an empty form-data entry to the end of the stream, wechat server will continue to read the stream and end themedia
part correctly. This hack do send some extra data but will not break the present implementation.
在上传的流的最后插入\r\n
博客园的新闻评论有问题,在新闻列表页面可以看到评论数增加了,但是点击新闻进入新闻内容页面显示的是之前的评论,只有点一下浏览器上的刷新,才会看到新的评论。
@Launcher: 谢谢反馈!我们查一下这个问题
curl_setopt ( $curl, CURLOPT_POSTFIELDSIZE, $len );
楼主,你的这个问题解决了没有??
我也遇到这个问题了。麻烦死了
在cli模式下,使用 curl命令就ok了。
比如切换到要上传的图片同路径下,使用下面的命令,后面的token换成自己的
curl -F media=@teacher.png -F type=image "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=36_iK1v