微信上传临时素材 。 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); }
被它害晕了,希望对你们有帮助 
  
 
 

你可能感兴趣的:(微信开发)