Php Development-upload temporary materials and php development materials. Php Development: Upload temporary materials. php development materials this article provides examples to share with you the specific code for php to upload temporary materials for your reference. the specific content is as follows: publicfuncti: Upload temporary materials for php development, php development materials
The example in this article shares the code for uploading temporary materials in php for your reference. The details are as follows:
Public function uploadImg ($ imgUrl) {$ TOKEN = $ this-> getAccessToken (); $ URL = 'http: // file.api.weixin.qq.com/cgi-bin/media/upload? Access_token = '. $ TOKEN. '& type = image'; $ data = array ('media' => '@'. $ imgUrl); $ result = $ this-> curl_post ($ URL, $ data); $ data = @ json_decode ($ result, true ); return $ data ['media _ id'];} public function getAccessToken () {$ url = 'https: // api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = wxe574b1bd35d7d4da & secret = comment '; $ result = json_decode ($ this-> curlGet ($ url), true ); return $ result ['Access _ token'];} function curl_post ($ url, $ data = null) {// create a new cURL resource $ curl = curl_init (); // Set the URL and the corresponding options curl_setopt ($ curl, CURLOPT_URL, $ url); if (! Empty ($ data) {curl_setopt ($ curl, CURLOPT_POST, 1); curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data);} curl_setopt ($ curl, expires, 1 ); // execute curl, capture the URL, and pass it to the browser $ output = curl_exec ($ curl); // Close the cURL resource and release the system resource curl_close ($ curl ); return $ output ;}
CallUploadImg ($ imgurl)Image transfer address parameters
Returned results
array ( 'type' => 'image', 'media_id' => 'W89mt3FEaxXOMOw0fLj2Cb6A8vfMjuXrj6XW59O3l9a7Tj_h2SjlBEr4dvp4Du2R', 'created_at' => 1464140301,
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.
Examples in this article share the code for uploading temporary materials to php for your reference. the specific content is as follows: public functi...