微信公众号开发---上传临时素材到公众号遇到的问题:"errcode":41005,"errmsg":"media data missing...

1、上传临时素材到公众号遇到的问题:"errcode":41005,"errmsg":"media data missing

解决办法:因为php版本的原因,上传素材一直保错。php的curl的curl_setopt 函数存在版本差异

php5.5已经把通过@加文件路径上传文件的方式给放入到Deprecated中了。php5.6默认是不支持这种方式了

特殊处理1:curl_setopt ( $ch, CURLOPT_SAFE_UPLOAD, false);

特殊处理2:$post_data ['media']  = '@'.$file;

具体实现代码如下

 

[php]  view plain  copy
 
  1. /* 上传多媒体文件 */  
  2.     public function uploadFile($file, $type = 'image', $acctoken = '') {  
  3.     //  $post_data ['type'] = $type; // 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)  
  4.         $post_data ['media']  = '@'.$file;  
  5.         //$post_data ['media']  =$file;  
  6.       
  7.         $url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=$acctoken&type=image";  
  8.       
  9.         $output=$this->http_post_media($url, $post_data);  
  10.   
  11.         return $output;  
[php]  view plain  copy
 
  1. }  
[php]  view plain  copy
 
  1. <pre name="code" class="php"> private function http_post_media($url,$strPOST)  
  2.     {  
  3.         $oCurl = curl_init ();  
  4.         curl_setopt ( $oCurl, CURLOPT_SAFE_UPLOAD, false);  
  5.         if (stripos ( $url, "https://" ) !== FALSE) {  
  6.             curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYPEER, FALSE );  
  7.             curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYHOST, false );  
  8.         }  
  9.   
  10.         curl_setopt ( $oCurl, CURLOPT_URL, $url );  
  11.         curl_setopt ( $oCurl, CURLOPT_RETURNTRANSFER, 1 );  
  12.         curl_setopt ( $oCurl, CURLOPT_POST, true );  
  13.         curl_setopt ( $oCurl, CURLOPT_POSTFIELDS, $strPOST );  
  14.         $sContent = curl_exec ( $oCurl );  
  15.         $aStatus = curl_getinfo ( $oCurl );  
  16.         curl_close ( $oCurl );  
  17.         if (intval ( $aStatus ["http_code"] ) == 200) {  
  18.             return $sContent;  
  19.         } else {  
  20.             return false;  
  21.         }  
  22.   
  23.     }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值