$request->file()獲取多文件, 為什么總是獲取最后一個(gè)文件。
這里寫(xiě)問(wèn)題描述
使用$request->file('img')獲取多文件,只能上傳一個(gè)。
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);
}
}