curl上传文件,图片

  public function upImg()

    {

        $token = $this->getToken();

        $data = array("img" => "@" . $this->imgUrl);

        $url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=" . $token . "&type=image";

        $res = json_decode($this->curl($data,$url),true);

        $this->imgMedia = $res['media_id'];

    }


 public function curl($data,$url)

    {

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

        curl_setopt($ch, CURLOPT_POST, 1);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        return curl_exec($ch);

        curl_close($ch);

    }

本文转自  陈小龙哈   51CTO博客,原文链接:http://blog.51cto.com/chenxiaolong/1712487

上一篇:jquery插件整理篇(六)HTML编辑器插件


下一篇:鼠标划过时,预览大图片(浮动层)