微信小程序上传图片

来源:互联网 发布:印度与中国 知乎 编辑:程序博客网 时间:2024/04/29 03:13
var app = getApp()Page({  data: {    selected: true,    selected1: false,    selected2: false,    img:[]  },chooseimage: function () {    var _this = this;    wx.chooseImage({      count: 7, // 默认9       sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有       sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有       success: function (res) {        console.log(res)        for(var i=0;i<res.tempFilePaths.length;i++){          wx.uploadFile({            header: { //这里写你借口返回的数据是什么类型,这里就体现了微信小程序的强大,直接给你解析数据,再也不用去寻找各种方法去解析json,xml等数据了              'Content-Type': 'application/json'            } ,                      url: 'http://192.168.8.60/Auth--master3/Auth--master/index.php/WxApi/wxOrder', //仅为示例,非真实的接口地址            filePath: res.tempFilePaths[i],            name: 'img',            formData: {              'img': res.tempFilePaths[i]            },            success: function (res) {              console.log(_this)             _this.setData({               img: _this.data.img.concat(JSON.parse(res.data).msg)             })              console.log(res)              var data = res.data              //do something            }          })        }    

后台程序

  //上传图片       if(isset($_FILES['img']) && $_FILES['logo']['error'] == 0){                      $info =img_upload();            $logo ="Public/"."upload/". $info['img']['savepath'].$info['img']['savename'];            exit(json_encode(array('code'=>'1','msg'=>$logo)));        }


原创粉丝点击