php怎么保存来自微信小程序的图片
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++;
}
}
})
},
})


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/ 目录下

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:165
阅读量:101
阅读量:163
阅读量:53
阅读量:77