小程序上传图片+php接口

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

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],
         
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值