微信上传媒体文件 报41005 解决方案 php的巨坑

此问题是因为php新版本更新,对函数的支持有改变导致的

解决如下

 $postMedia = array();
       $postMedia['access_token'] = $json->access_token;
       $postMedia['type'] = 'image';

       foreach ($imgs as $img) {
           file_put_contents(CONF_PATH . 'img_' . $img['id'] . '.jpg', file_get_contents($img['pic']));
           //$postMedia['media']=$_SERVER['DOCUMENT_ROOT'].str_replace('http://'.$_SERVER['HTTP_HOST'],'',$img['pic']);
           //$postMedia['media']=$_SERVER['DOCUMENT_ROOT'].str_replace('./','/',CONF_PATH.'img_'.$img['id'].'.jpg');
           // @只支持 5.5以下版本
           //$postMedia['media']=CONF_PATH.'img_'.$img['id'].'.jpg';
//$postMedia['media']=$_SERVER['DOCUMENT_ROOT'].str_replace(array('./'),array('/'),$postMedia['media']);
           $filePath = CONF_PATH . 'img_' . $img['id'] . '.jpg';
           $filePath = $_SERVER['DOCUMENT_ROOT'] . str_replace(array('./'), array('/'), $filePath);
           //CURLFile()只支持php5.6以上版本,
           $postMedia['media'] = new CURLFile($filePath);

           $rt = $this->curlPost('http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=' . $postMedia['access_token'] . '&type=' . $postMedia['type'], array('media' => $postMedia['media']));

           if ($rt['rt'] == false) {
               $this->error('操作失败,curl_error:' . $rt['errorno']);
           } else {
               $mediaids .= $rt['media_id'];
               $comma = ',';
           }
       }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值