您现在的位置: 首页 > 微信小程序开发 > 教程 >

小程序上传多张图片到服务器

来源:微信小程序 编辑:Yiyongtong.com 发布时间:2017-11-08 14:30热度:
// 点击选择图片
choose: function (e) {
var that = this
var uniacid = wx.getStorageSync(‘uniacid’)
wx.chooseImage({
count: 9, // 默认9
sizeType: [‘original’, ‘compressed’],
sourceType: [‘album’, ‘camera’],
success: function (res) {
console.log(res)
var img = res.tempFilePaths
var tempFilePaths = new Array(img.length)
// var tempFilePaths = []
console.log(tempFilePaths)
for (let i = 0; i < tempFilePaths.length;i++){
wx.uploadFile({
url: that.data.url + ‘app/index.php?i=’ + uniacid + ‘&c=entry&a=wxapp&do=upload&m=zh_hdbm’,
filePath: img[i],
name: ‘upfile’,
formData: {},
success: function (res) {
tempFilePaths[i] = res.data
that.setData({
tempFilePaths: tempFilePaths
})
},
fail: function (res) {
// console.log(res)
},
})
}
that.setData({
logo: res.tempFilePaths
})
}
})
},