前端
JS
fileupdate: function(){
let inputDOM = this.$refs.inputer;
this.file = inputDOM.files[0];
var formdata = new FormData();
formdata.append('fileSelect',inputDOM.files[0]);
axios.post('/test/import',{
params: {
testId:this.testId,
}
})
axios({ url: '/test/import',
method: 'post',
data: formdata,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
},
后端(注意文件编码)
//excel导入
public function import(Request $request){
$filePath = $request->file('fileSelect');
Excel::load($filePath,function($reader) {
$data = $reader->all();
var_dump($data);
},'gbk');
}
$data = Excel::load($path,function ($reader) {},'GBK')->get();
原文链接:https://www.f2er.com/laravel/60453.html