zoukankan      html  css  js  c++  java
  • 微信上传素材返回 '{"errcode":41005,"errmsg":"media data missing"}',php5.6返回

    问题描述:

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

    解决办法curl处理

    function curl_post($url, $data, $header = array()){
                if(function_exists('curl_init')) {
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, $url);
                    if(is_array($header) && !empty($header)){
                        $set_head = array();
                        foreach ($header as $k=>$v){
                            $set_head[] = "$k:$v";
                        }
                        curl_setopt($ch, CURLOPT_HTTPHEADER, $set_head);
                    }
                    curl_setopt($ch, CURLOPT_HEADER, 0);
                    curl_setopt($ch, CURLOPT_POST, 1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    curl_setopt($ch, CURLOPT_TIMEOUT, 0);// 1s to timeout.
                    $response = curl_exec($ch);
                    if(curl_errno($ch)){
                        //error
                        return curl_error($ch);
                    }
                    $reslut = curl_getinfo($ch);
                    print_r($reslut);
                    curl_close($ch);
                    $info = array();
                    if($response){
                        $info = json_decode($response, true);
                    }
                    return $info;
                } else {
                    throw new Exception('Do not support CURL function.');
                }
        }
    
    $file = "a.jpg";
    $data = array(
    			'media'=> new CURLFile($file)
    		);
    		$result = $this->curl_post(self::WEIXIN_API . 'media/upload?access_token=' . $this->get_access_token($app_id, $app_secret) . '&type=' . $type ,$data);
    
  • 相关阅读:
    利用 FFmpeg 和 ImageMagick, AVI 转 GIF(不失真)
    TinyMCE textarea 输入框外部程序动态修改方法
    eclipse快速向下复制行
    ${factoryList }后面有空格不影响
    pre标签
    js备忘录_2
    eclipse 中 大小写切换:ctrl+shift+x 转为大写 ctrl+shift+y 转为小写
    js备忘录_1
    缓存
    myeclipse bug
  • 原文地址:https://www.cnblogs.com/padog/p/6150516.html
Copyright © 2011-2022 走看看