This article brings you the content is about PHP to get temporary material (with code), there is a certain reference value, the need for friends can refer to, I hope to help you.
Note: 1: Media files are stored in the background for 3 days, that is, after 3 days, the media_id expires.
2: Temporary footage media_id is reusable.
If it is php5.3 below the path path needs to take @, plus the absolute path of the text, more than 5.3 of the version needs to use the new Curlfile () class to obtain an absolute address
$path = new Curlfile (Realpath (' g:/xampp/htdocs/wx/app/zan.jpg ')), $path = $path->name;//absolute path $type = ' images ';// Thumb$res = $this->upload_media (' image ', $path);//Get media_id of footage, valid for 3 days $media_id = $res->media_id;// The following is the get temporary footage Url$url = $this->get_media ($media _id);//Get URL to temporary footage public function Upload_media ($type, $path) {$ url = ' https://api.weixin.qq.com/cgi-bin/media/upload?access_token= '. $this->get_access_token (). ' &type= '. $type; $res = $this->upload ($url, Array (' media ' = ' @ '. $path)); Determines whether a successful return $res is invoked; } Public Function Get_media ($media _id) {return ' https://api.weixin.qq.com/cgi-bin/media/get?access_token= ' . $this->get_access_token (). ' &media_id= '. $media _id; }/* Upload pictures. Graphic Dedicated */public static function upload ($url, $filedata) {$curl = Curl_init (); if (class_exists ('/curlfile ')) {//php5.5 differs from Curlopt_safe_upload's default value in php5.6 curl_setopt ($curl, CurloPt_safe_upload, True); } else {if (defined (' Curlopt_safe_upload ')) {curl_setopt ($curl, Curlopt_safe_upload, FALSE); }} curl_setopt ($curl, Curlopt_url, $url); curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE); curl_setopt ($curl, Curlopt_ssl_verifyhost, FALSE); if (! empty ($filedata)) {curl_setopt ($curl, Curlopt_post, 1); curl_setopt ($curl, Curlopt_postfields, $filedata); } curl_setopt ($curl, Curlopt_returntransfer, 1); $output = curl_exec ($curl); Curl_close ($curl); return $output; }