js代码
bindViewTap: function () {
var that = this;
console.log(that.data.hits)
var hit = that.data.hits
hit = hit+1;
that.setData({
hits:hit
})
// 多张图片
if (hit <= 3) {
wx.chooseImage({
count: 3,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success(res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths;
that.data.imgsrc.push(tempFilePaths);
var list = [];
that.data.imgsrc.forEach(function (item, index) {
//这里的item就是从数组里拿出来的每一个数组
var obj = {
'filesrc': item[0],
}
list.push(obj);
that.setData({
family: list,
})
})
console.log(that.data.family);
// 成功之后上传到服务器
wx.uploadFile({
url: app.globalData.requesturl,
filePath: tempFilePaths[0],

本文介绍了一种在小程序中实现图片上传的方法,并结合PHP编写了相关接口。提供了JS代码和WXML代码示例,可以直接应用于项目。博主鼓励读者在评论区交流问题和改进建议。
最低0.47元/天 解锁文章
227

被折叠的 条评论
为什么被折叠?



