I used to use version 2.1.4. After seeing the update, I tried it and found that there were many changes.
First, introduce js and css
-
<link rel="stylesheet" href="uploadify.css" />
-
<script src="jquery.uploadify.js"></script>
-
Of course, jquery is essential
Next is the code:
-
-
$(function() {
-
$("#uploadify").uploadify({
-
'auto' : false,
-
'method' : "post",
-
'height' : '20',
-
'width' : '100',
-
'swf' : 'uploadify.swf',
-
'uploader' : '<%=basePath%>/contract/fileUpload.action',
-
'fileTypeDesc' : 'format:txt,xls,xlsx,doc,docx',
-
'fileTypeExts' : '*.txt;*.xls;*.xlsx;*.doc;*.docx;*.zip',
-
'fileSizeLimit' : '10000KB',
-
'buttonText' : 'Select file',
-
'fileObjName' :'uploadify',
-
'successTimeout' : '5',
-
'requeueErrors' : false,
-
'removeTimeout' : '1',
-
'removeCompleted' : true,
-
'onUploadSuccess' : function(file, data, response){
-
var attach = eval('(' + data + ')');
-
$("#fileTable").show();
-
var addHtml = "<tr>"+
-
"<td class='t_l'>"+
-
"<a href='<%=basePath%>/attach/downloadAttach.action?attachId="+attach.id+"'>"+attach.filename+"."+attach.fileextname+"</a>"+
-
"</td>"+
-
"<td class='t_r'>"+attach.filesize+"</td>"+
-
"<td class='t_c'>"+attach.uploaddate+"</td>"+
-
"<td class='t_c'><a href='<%=basePath%>/attach/downloadAttach.action?attachId="+attach.id+"' id='"+attach.id+"'>download</a></td>"+
-
"<td class='t_c'><a href='#' onclick='removeFile(this)' id='"+attach.id+"' name='attach_id'>cancel</a></td>"+
-
"</tr>";
-
$("#fileBody").append(addHtml);
-
}
-
});
-
});
Where onUploadSuccess is the callback function after successful upload file is the uploaded file. You can get the file name size through file.name to get the size
data is the string output by the background reponse. In the above example, the output is a json object, so eval is used for conversion
response is the result true or false. Please refer to official documents for details.
-
<td colspan="3">
-
<input type="file" name="uploadify" id="uploadify" />
-
<input type="button" value="upload" onclick="$('#uploadify').uploadify('upload','*');">
-
<input type="button" value="cancel" onclick="$('#uploadify').uploadify('stop');">
-
<table style="display: none;" id="fileTable">
-
<tbody style="width: 550px;border: solid;border-color: #D0D0D3;" id="fileBody">
-
<tr style="border: solid;border: #D0D0D3;">
-
<td width="200px;" class="t_c">file name</td>
-
<td width="100px;" class="t_c">Size(k)</td>
-
<td width="150px;" class="t_c">Upload time</td>
-
<td width="100px;" class="t_c" colspan="2">operation</td>
-
</tr>
-
</tbody>
-
</table>
-
</td>
You can see that many properties in the initialization have changed, including the function name of the upload operation and so on.
Secondly, there is another problem. The button of uploading the file in IE9 can't be clicked. The initial check may be caused by the problem of flash. Baidu later found that the classid in the source js can be modified.
For details, please refer to:
http://www.cnblogs.com/donhwa/archive/2011/06/23/ie9_swfupload_bug.html
js replacement file download after solving this problem
http://files.cnblogs.com/lostboy/jquery.uploadify3.1.fixed.js
or
http://download.csdn.net/detail/chenxiang199055/6003627