Upload a single picture and display:

<button bindtap="upimg" class='jia_img' >upload</button>
<image src="{{tempFilePaths[0]}}"></image>
Copy the code
data{
tempFilePaths: []; },upimg: function () {
    wx.chooseImage({
      success: function (res) {
        var data = {
          program_id: app.jtappid
        }
        var tempFilePaths = res.tempFilePaths  / / picture
        wx.uploadFile({
          url: 'aaa.cn'.// This is an example, not a real interface address
          filePath: tempFilePaths[0].name: 'add_image'.// The file's corresponding parameter name (key)
          formData: data,  // Other form information
          success: function (res) {}})})},Copy the code

Upload multiple pictures and display:

<view class="big-logos">
  <image bindtap="upimg" src='.. /.. /.. /image/s.png'></image>
  <block wx:for="{{img_arr}}" wx:key="index">
    <view class='logoinfo'>
      <text class='xxx' bindtap='xxx' data-index='{{index}}'>x</text>
      <image src='{{item}}'></image>
    </view>
  </block>
</view>
<button class='top_20 btn' bindtap="upconfirm">determine</button>
Copy the code
  upconfirm: function () {
    this.up();
  },
  up: function () {
    var that = this;
    data = {
      openid: app.openid,
      program_id: app.program_id,
      only_num: only_num
    }
    wx.uploadFile({
      url: 'pg.php/Aishen/upload_photo'.filePath: that.data.img_arr[i],
      name: 'image'.// The file's corresponding parameter name (key)
      formData: data,  // Other form information
      success: function (res) {},complete: function (complete) {
        console.log(complete)
        i++
        if (i == that.data.img_arr.length) {
          util.request('https://sz800800.cn/pg.php/Aishen/uploade_photo_r'.'post', { 'only_num': only_num }, 'Loading data'.function (res) {
            console.log(res)
            if (res.data.state == 1) {
              wx.showModal({
                title: 'tip'.content: 'Submission successful! '.success: function (res) {
                  that.onLoad()
                  wx.navigateBack({
                    delta: 1})}})}else {
              wx.showModal({
                title: 'tip'.content: 'Submit failed, please resubmit! ',})}})}else if (i < that.data.img_arr.length) {// If the image is not completed, continue to call the function
          that.up()
        }
      }
    })
  },
Copy the code
  / / upload
  upimg: function () {
    var that = this;
    if (this.data.img_arr.length < 12) {
      wx.chooseImage({
        sizeType: ['original'.'compressed'].success: function (res) {
          that.setData({
            img_arr: that.data.img_arr.concat(res.tempFilePaths)
          })
          num = that.data.img_arr.length
        }
      })
    } else {
      wx.showToast({
        title: 'Upload up to 12 images'.icon: 'loading'.duration: 3000}); }},Copy the code