【发布时间】:2019-09-29 18:30:18
【问题描述】:
我有一个 html 动态表单一个公司的下拉列表。如果 用户将从显示的下拉列表中选择任何公司 表中特定公司的各自员工。i 的每一行 我正在附加输入[文件]。现在用户将上传每个人的工资单 员工并保存数据。我关心的是把每行文件上传到 数据库到不同的行。
component.html:
<table *ngIf="allemp">
<tr>
<th>ID</th>
<th>Name of Employee</th>
<th>Attached Payslip</th>
</tr>
<tr *ngFor="let data1 of allemp">
<td>{{data1.id}}</td>
<td>{{data1.emp_name}}</td>
<input formArrayName='payslip' type="file" (change)="onFileChangeInfo($event,i)" multiple></td>
</tr>
</table>
ts文件中的多个上传功能:
onFileChangeInfo(event,index) {
const reader = new FileReader();
var filesAmount = event.target.files.length;
this.items= this.myForm1.controls['payslip'] as FormArray;
console.log(this.items);
if(event.target.files && event.target.files.length > 0) {
const [files] = event.target.files;
this.regInfoName=event.target.files[0].name;
this.urlInfoUploadd= event.target.result;
for (let i = 0; i < filesAmount; i++) {
reader.readAsDataURL(event.target.files[i]);
reader.onload = () => {
this.urlInfoUpload = this.urlInfoUploadd;
this.regInfoNameHtml=this.regInfoName;
this.items.controls[index].patchValue({
'data_blob': reader.result,
'data_file':files.name,
});
console.log(files.name);
this.cd.markForCheck();
};
}
}
}
在 console.log(filesAmount) 上它显示了所有选定的文件。但在数据库中只有最后一个文件。
我不明白我的代码有什么问题。请帮助我。
【问题讨论】:
标签: php laravel angular7 multiple-file-upload