天天看點

jquery.fileupload 批量上傳

<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'

});

}

})

});

function uploadFiles(){

$('#fileupload').click();

};

</script>

<input id="fileupload" type="file" name="files" multiple style="display: none">

<a data-btn="btn_upload_many" οnclick="uploadFiles();" href="javascript:void(0);" target="_blank" rel="external nofollow" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'">批量上傳</a>

private File files;// 檔案 批量上傳使用

private String filesFileName;// 檔案名稱 批量上傳使用

private String filesContentType;// 檔案類型 批量上傳使用

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