1. 程式人生 > >微信上傳臨時素材 。 php7.1.3 總是報41005 最佳解決方案

微信上傳臨時素材 。 php7.1.3 總是報41005 最佳解決方案

 public function imagetwoAction(){
        
        $path="yaf/application/admin/controllers/uploads_picture_2017-05-03_5909d692c2c84.png";//絕對路徑,不可以是外鏈
        //獲取token
        $type="image";
        $token=$this->accessTokenAction();
        echo $token;die;
        $url='https://api.weixin.qq.com/cgi-bin/media/upload?access_token=' . $token .'&type='.$type;
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
        $data = array('file' => new \CURLFile(realpath($path)));//
php 版本
>=5.5
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, 1 ); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_USERAGENT,"TEST"); $result = curl_exec($curl); $res=json_decode($result,true); var_dump($res);// {"type":"image","media_id":"rzUIbuA6WjuLoKbEqP5vdJ2VreLZb1lUSxSnu7oKs_aX8Sfi2mfXu7KFQ3SgEhoJ","created_at":1504744175}// 'type' => string 'image' (length=5)// 'media_id' => string '0gpDsvr8EllWLqkBO5r2SsTzwacYFQtCHWomLq4jIkoo4V2iGBt_k3DJir2ViO-M' (length=64)// 'created_at' => int 1504744709 $error = curl_error($curl); }
被它害暈了,希望對你們有幫助