jquery.fileupload 批量上传

本文介绍了一个使用jQuery和EasyUI实现的批量文件上传功能,并详细展示了如何通过JavaScript处理文件上传的过程,包括进度提示、成功反馈等。此外还提供了服务器端处理文件的方法。

<script>
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
url:'${pageContext.request.contextPath}/qua/quaCheckAction!checkUploadFile.action',
start: function (e, data) {
parent.$.messager.progress({
title : $.i18n.prop('msg_show_title'),
text : $.i18n.prop('msg_show_text')
});
},
stop:function(){
parent.$.messager.progress('close');
$.messager.show({
title:$.i18n.prop('msg_show_title'),
msg:$.i18n.prop('upload_success'),
timeout:5000,
showType:'slide'
});
}
/* done: function (e, data) {
debugger
parent.$.messager.progress('close');
//导入成功
$.messager.show({
title:$.i18n.prop('msg_show_title'),
msg:$.i18n.prop('upload_success'),
timeout:5000,
showType:'slide'
});
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
} */
})
});

function uploadFiles(){
$('#fileupload').click();
};

</script>

 

 

<input id="fileupload" type="file" name="files" multiple style="display: none">
<a data-btn="btn_upload_many" onclick="uploadFiles();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'">批量上传</a>

 

 

 

private File files;// 文件 批量上传使用
private String filesFileName;// 文件名称 批量上传使用
private String filesContentType;// 文件类型 批量上传使用

/**
* @liutt
* 批量上传时使用该方法上传
*/
public void checkUploadFile(){

//String filePath = getSavePath(); // 获取文件夹的路径

String url = ServletActionContext.getServletContext().getRealPath("/");
File file = new File(url);
String newFilePath = file.getParentFile().getParentFile().getParentFile().getPath()+"/check";
File newFile = new File(newFilePath);
// 如果不存在文件夹 就创建一个文件夹
if (!newFile.exists() && !newFile.isDirectory()) {
newFile.mkdirs();
}
// 获取文件夹的路径 和 重命名后的文件的名称
String checkfilepath = newFile.getPath() + "\\" + getFilesFileName();
try {
FileUtils.wirteFile(checkfilepath, getFiles());
//将文件路径和数据库进行绑定
quaCheckFileService.saveQuaCheck(getFilesFileName(), "check");
} catch (Exception e) {
e.printStackTrace();
super.writeJson("error");
return;
}
}

转载于:https://www.cnblogs.com/liutt1989/p/6401077.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值