$request->file()获取多文件, 为什么总是获取最后一个文件。
这里写问题描述
使用$request->file('img')获取多文件,只能上传一个。
uniapp的前端代码
var data = this.imgarr.map((file, index) => ({
name: 'img[]',
filePath: file,
}));
uni.uploadFile({
url: this.url + 'upload_img',
files: data,
formData: {
type: 'img'
},
success: (rs) => {
this.tijiao(JSON.stringify(JSON.parse(rs.data).arr));
},
fail: () => {
this.showToast('图片文件上传失败!');
}
})
后端
$files = $request->file('img');
foreach ($files as $i => $file) {
if ($file->isValid()) {
$savePath = public_path() . '/static/'.$type.'/' . $file->getUploadName();
$arr[] = '/static/'.$type.'/' . $file->getUploadName();
$file->move($savePath);
}
}
已解决!!!