php怎么保存来自微信小程序的图片

 时间:2026-02-14 23:57:31

1、微信小程序端:

var api = require('../../config/api.js');


const sourceType = [['camera'], ['album'], ['camera', 'album']]
const sizeType = [['compressed'], ['original'], ['compressed', 'original']]
Page({
  onShareAppMessage() {
    return {
      title: '图片',
      path: 'page/API/pages/image/image'
    }
  },
  data: {
    imageList: [],
    sourceTypeIndex: 1,
    sourceType: ['拍照', '相册', '拍照或相册'],
    sizeTypeIndex: 1,
    sizeType: ['压缩', '原图', '压缩或原图'],
    countIndex: 0,
    count: [1, 2, 3, 4, 5, 6, 7, 8, 9]
  },
  sourceTypeChange(e) {
    this.setData({
      sourceTypeIndex: e.detail.value
    })
  },
  sizeTypeChange(e) {
    this.setData({
      sizeTypeIndex: e.detail.value
    })
  },
  countChange(e) {
    this.setData({
      countIndex: e.detail.value
    })
  },
  chooseImage() {
    const that = this
    wx.chooseImage({
      sourceType: sourceType[this.data.sourceTypeIndex],
      sizeType: sizeType[this.data.sizeTypeIndex],
      count: this.data.count[this.data.countIndex],
      success(res) {
        var bookDetail = wx.getStorageSync('bookDetail')
        that.setData({
          imageList: res.tempFilePaths
        })
        const tempFilePaths = res.tempFilePaths
        var i = 0;
        for (var tempFilePath in tempFilePaths) {
          wx.uploadFile({
            url: api.SellerQrcode,//此处是图片接口地址
            filePath: tempFilePaths[i],
            name: 'file',
            formData: {
              'sid': bookDetail.sid,
              'qrcode' : 1
            },
            success(res) {
              const data = JSON.parse(res.data)
              const code = data.code;
              if(code!=1){
                wx.showToast({
                  title: '请上传图片',
                  icon: 'none',
                  duration: 3000
                })
                that.setData({
                  imageList: []
                })
              }
            }
          })
          i++;
        }
      }
    })
  },
})

php怎么保存来自微信小程序的图片

php怎么保存来自微信小程序的图片

2、php后台:

我是用的是thinkphp框架,主要代码如下:

(1)use think\Request;

(2)$file = request()->file('file');//后台获取图片

(3)$info = $file->validate(['size'=>5 * 1024 * 1024,'ext'=>'jpg,png,jpeg'])->rule('uniqid')->move(ROOT_PATH . 'public' . DS . 'uploads'.DS.$date);// 移动到框架应用根目录/public/uploads/ 目录下

php怎么保存来自微信小程序的图片

  • 网站的seo怎么做
  • 声宝TQ-G9051CL型料理锅说明书
  • 在新网买的域名和空间怎么绑定?
  • 女人如何预防提前进入更年期
  • VTB-9E/10-C-NB(15KW) 无触点停电保磁控制柜使用说明:[1]
  • 热门搜索
    怎么打蝴蝶结视频 龃龉怎么读 貔貅怎么摆放 老是失眠怎么办 梅花手表怎么样 声明怎么写 三国群英传7怎么玩 雷诺手表怎么样 地热不热怎么办 林清轩怎么样