PHP微信上传永久图片素材
Posted 张志建
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP微信上传永久图片素材相关的知识,希望对你有一定的参考价值。
$TOKEN="XXXX"; $file = "D:wwwweixingame.jpg"; $data = array( ‘media‘=> new CURLFile($file) ); $url = ‘https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=‘.$TOKEN.‘&type=image‘; $result = curl_posts($url,$data); var_dump($result); function curl_posts($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. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $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.‘); } }
以上是关于PHP微信上传永久图片素材的主要内容,如果未能解决你的问题,请参考以下文章