微信小程序上传图片

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))); 
       }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值