在上篇文章[laravel微信公众号开发](https://www.yuanchengzhushou.cn/article/8046.html)我们已经讲过公众号开发
这里假设你已经入门了公众号开发,
当我们向公众号上传素材如图片时发现报错,提示errcode":41005,"errmsg":"media data missing
百度发现问题
如何解决
```
$access_token = Redis::get('weixin_access_token');
$url="https://api.weixin.qq.com/cgi-bin/media/upload?access_token=$access_token&type=image";
//$fields=array("media"=>"@"."/tmp/1.jpg"); //这是旧的写法,会报标题的错误`
```
`$fields = array("file" => new \CURLFILE("/app/www/laravel-wechat/voice/pic.jpg")); //这是正确的写法`
```
$result = $this->httpGet($url,$fields);
print_r($result);
public function httpGet($url,$fields='') {
$curl = curl_init();
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//输出内容为字符串
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
if (curl_errno($curl)) {
return 'Errno'.curl_error($curl);
}
curl_close($curl);
#$array = $this->jsontoarray($res);
return $res;
}
```