网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 生活知识 知识问答

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

时间:2024-10-18 07:50:39

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怎么保存来自微信小程序的图片
© 2026 阿力知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com