点击按钮直接上传文
/*批量导入*/
/*#load:为按钮,点击后生成一个隐藏的input file标签*/
$('#load').after('<input type="file" id="load_xls" name="file" style="display:none" onchange ="uploadFile()">');
$('#load').click(function(){
document.getElementById("load_xls").click();
});
function uploadFile() {
var myform = new FormData();
myform.append('file',$('#load_xls')[0].files[0]);
$.ajax({
url: "admin.php?r=org/orguser/addusers",
type: "POST",
data: myform,
contentType: false,
processData: false,
success: function (data) {
console.log(data);
},
error:function(data){
console.log(data)
}
});
}
后台接受
if (request()->file('file') != null){
echo "00000";
}else{
echo "111111";
}
2,打包form表单进行上传文件