一般我们获取多个文件上传的数据的时候,我们需要进行数据的获取下面直接贴上代码:
<form name="" id="upfile" enctype="multipart/form-data"> <input type="file" name="dimission_apply" id="dimission_apply" class="inputFile "> <input type="file" name="dimission_assoc" id="dimission_assoc" class="inputFile "> <input type="file" name="dimission_work_assoc" id="dimission_work_assoc" class="inputFile "> <input type="file" name="dimission_consumable" id="dimission_consumable" class="inputFile "> <div class="btn btn-success text-center" onclick="upfile({$perFlowId});">提交上传文件</div> </form>
<script> function upfile(id) { var formData = new FormData(); $sign ="1"; if ($("#dimission_report").val() == ''){ $sign = "2";alert('请上传辞职报告!'); }else if ($("#dimission_apply").val() == ''){ $sign = "2";alert('请上传员工离职申请表!'); }else if ($("#dimission_assoc").val() == ''){ $sign = "2";alert('请上传离职交接表!'); }else if ($("#dimission_work_assoc").val() == ''){ $sign = "2";alert('请上传离职人员工作交接表!'); }else if ($("#dimission_consumable").val() == ''){ $sign = "2";alert('请上传工具耗材交接表!'); }else{ formData.append("dimission_report",$("#dimission_report")[0].files[0]); formData.append("dimission_apply",$("#dimission_apply")[0].files[0]); formData.append("dimission_assoc",$("#dimission_assoc")[0].files[0]); formData.append("dimission_work_assoc",$("#dimission_work_assoc")[0].files[0]); formData.append("dimission_consumable",$("#dimission_consumable")[0].files[0]); } if ($sign == '1') { $.ajax({ type:'post', data:formData, cache: false, processData: false, contentType: false, async: false, url:'/index.php/Home/dimission/personal_data_upfile.html?id='+id+'&type=dimission', success:function (data) { if (data == '1'){ alert('上传成功'); }else if(data == '2'){ alert('上传失败'); }else{ alert(data); } } }) } </script>