上次用到了uploaddify2,这次写下Uploadify v3.2.1的使用,后台代码都一样,区别就是前台js的地方,Uploadify的参数和方法名称有变化。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>uploadify3</title>
<link href="../js/uploadify3/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/uploadify3/jquery.uploadify.min.js"></script>
<script type="text/javascript">
var desc = '*.doc;*.docx;*.xls;*.xlsx;*.pdf';
var sizeLimit = 10;
$(function(){
jQuery("#fileQueue").uploadify({
'swf': '../js/uploadify3/uploadify.swf?var='+(new Date()).getTime(),
'uploader': '../uploadify2Controller/uploadfiles.do',
'method': 'get',
'fileSizeLimit' : sizeLimit*1024*1024,
'queueID': 'fileQueue',
'fileTypeExts':desc,
'multi': false,
'auto':false,
'removeTimeout':1,
'buttonImage':'../js/uploadify2/liulan_bg.gif',
'onSelectError':function(file, errorCode, errorMsg) {
if(file!=null && file.type=="File Size"){
alert("文件不能大于"+sizeLimit+"M");
}else{
alert("文件上传异常");
}
},
'onSelect':function(event,queueID,fileObj) {
var companyName = $('#companyName').val();
if (companyName == "" || companyName == null) {
alert("请填写单位名称!");
return false;
}
var contactPhone = $('#contactPhone').val();
if (contactPhone == "" || contactPhone == null) {
alert("请填写联系方式!");
return false;
}
},
'onUploadSuccess':function(file, data, response) {
alert("上传成功");
}
});
});
function exeUpload(){
if(window.confirm('是否确认上传?')){
$("#fileQueue").uploadify("settings", "formData", { 'ctrlid': '11' });
$('#fileQueue').uploadify('upload','*');
}else{
return false;
}
}
function trim(str){
return str.replace(/(^\s*)|(\s*$)/g, "");
}
</script>
</head>
<body>
<div>
单位名称:<input type="text" id="companyName" name="companyName" /><br />
联系方式:<input type="text" id="contactPhone" name="contactPhone" />
<input type="button" onclick="javascript:exeUpload()" value="上传" />
<div id="fileQueue"></div>
</div>
</body>
</html>