标签:$resource submit post 斜杠 logs eth 字符 secret down
(转 https://www.cnblogs.com/phonecom/p/08859d91a2dac3c409f5859dcb36cb48.html)
上传、获取临时素材文件,媒体文件类型有图片(image)、语音(voice)、视频(video),普通文件(file) ,这里以上传、下载图片为例
<form action="<{$upload_url}>" name="file" method="POST" enctype="multipart/form-data"> <input type="file" name="image_file" value="选择"> <input type="submit" value="上传">private function upload_image($image_file) { $access_token = $this->get_access_token($this->corpid, $this->corpsecret); $type = ‘image‘; //这里是个坑,临时文件不能上传,需要保存到某个路径下再上传 $upload_dir = SYSTEM_DATA . "upload/test/"; !is_dir($upload_dir) and mkdir($upload_dir, 0755, true); $file_path = $upload_dir . $image_file["name"]; //这里用move_uploaded_file也可以 copy($image_file["tmp_name"], $file_path); $post_data = array( //这里是个坑,要在前面加@(@是禁止将字符串中的斜杠解释为转义字符) "media" => "@" . $file_path, ); $url = ‘https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=‘ . $access_token . ‘&type=‘ . $type; $array_result = json_decode($this->https_request($url, $post_data), TRUE); return $array_result[‘media_id‘]; }
private function download_image($media_id) { $access_token = $this->get_access_token($this->corpid, $this->corpsecret); $url = ‘https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=‘ . $access_token . ‘&media_id=‘ . $media_id; $a = file_get_contents($url); //以读写方式打开一个文件,若没有,则自动创建 $download_dir = SYSTEM_DATA . "download/test"; !is_dir($download_dir) and mkdir($download_dir, 0755, true); $resource = fopen($download_dir."/$media_id.jpg" , ‘w+‘); //将图片内容写入上述新建的文件 fwrite($resource, $a); //关闭资源 fclose($resource); }标签:$resource submit post 斜杠 logs eth 字符 secret down
原文地址:https://www.cnblogs.com/alexguoyihao/p/9259002.html