<head>?
<title>ajaxFileUpload文件上傳例子</title>?
<script?type="text/javascript"?src="<%=baseURL%>/kinth/js/ajaxfileupload.js"></script>?
<script?type="text/javascript">?
var?flag=0;?//flag作用:分兩種情況提交信息,如果是修改操作,沒有修改上傳文件,只修改其他字段的信息時點保存也能提交信息?
function?uploadFile(){?
$.ajaxFileUpload({?
url:baseURL+?"/fileCatalog.do?method=save",//需要鏈接到服務器地址?
secureuri:true,?
fileElementId:'file',//文件選擇框的id屬性?
success:?function(data,?status){?
var?results?=?$(data).find('body').html();?
var?obj?=?eval("("+results+")");?
$("#fileSize").val(obj.fileSize);?
$("#fileUrl").val(obj.fileUrl);?
$('#fileCatalogForm').submit();?
},error:?function?(data,?status,?e){?
showDialogWithMsg('ideaMsg','提示','文件錯誤!');?
}?
});?
}?
function?getFileName(obj)?
{?
flag=1;?
var?pos?=?-1;?
if(obj.value.indexOf("/")?>?-1){?
pos?=?obj.value.lastIndexOf("/")*1;?
}else?if(obj.value.indexOf("\\")?>?-1){?
pos?=?obj.value.lastIndexOf("\\")*1;?
}?
var?fileName?=?obj.value.substring(pos+1);?
$("#fileName").val(fileName);?
$('.files').text(fileName);?}?
function?ev_save(){?
if(submitMyForm('fileCatalogForm')){?
if(flag==0){?$('#fileCatalogForm').submit();?
}else{?uploadFile();?
}}?
}? function?ev_back(){?window.location.href=baseURL+'/fileCatalog.do?method=list';?
}?
</script>?
</head>?
<body>?
<html:form?styleId="fileCatalogForm"?action="/fileCatalog.do?method=save&fileFlag=true"?method="post"?enctype="application/x-www-form-urlencoded"?style="text-align:left;">?
<table>?
<tr>?
<td>附件上傳:</td>?
<td?style="text-align:left;"?id="fileTd">?
<input?type="file"?name="file"?id="file"?onChange="getFileName(this);"?/><br?/>?
</td>?
<td?colspan="2"?class="tdr">?
<ol?class=files>?
<c:if?test="${entity.resourceId?!=?null?&&?entity.resourceId?!=?''}"><li>?${entity.fileName} 上傳成功</li></c:if>?
</ol>?
</td>?
</tr>
<c:if?test="${entity.resourceId?==?null?||?entity.resourceId?==?''}">?
<input?type="text"?name="fileSize"?id="fileSize"?>?
</c:if>?
<input?type="hidden"?id="fileUrl"?name="fileUrl"?value="${entity.fileUrl}"
</table>?
</html:form>?
</body>