import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
@Controller
@ParentPackage("default")
@Namespace("/")
@Action(value = "upload", results = {
})
public class FileUploadAction extends ActionSupport{
}
二,页面代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.7.js"></script>
<script src="uploadify/jquery.uploadify.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="uploadify/uploadify.css">
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
auto:false,
fileObjName:'videoObj',
removeCompleted:false,
fileSizeLimit:'300000',//500M
//fileTypeExts:'*.mp4',//'*.*' 这个参数只能限制为一种类型,不能与下面的fileType同时使用,除非只有一种类型
//fileType:'mp4,swf',//自定义文件类型
//uploadLimit:10,//上传文件个数
swf : 'uploadify/uploadify.swf',
uploader : 'upload',
onUploadSuccess : onUploadSuccess
});
$("#file_upload-queue .cancel a").live("click",function(){
var divId = $(this).parent().parent().attr("id");
var fileId = $("#"+divId).find("input").attr("id");
if(typeof(fileId)=='undefined'){
if(confirm("确定要删除么?")){
$("#"+divId).fadeOut(500, function() {
$("#"+divId).remove();
});
$("#file_upload").uploadify('cancel', divId);
}
}else{
if(confirm("已经上传至服务器了,确定要删除么?")){
alert("发送请求删除,,再移除掉!");
$("#"+divId).fadeOut(500, function() {
$("#"+divId).remove();
});
$("#file_upload").uploadify('cancel', divId);
}
}
});
});
function upload(){
$('#file_upload').uploadify('upload', '*');
}
function stop(){
$('#file_upload').uploadify('stop', '*');
}
function onUploadSuccess(file, data, response){
//上传完成之后,调用的方法,可以获取从后台传递过来的数据(data)
//alert(jQuery.parseJSON(data).result);
//response == true;
//alert(file.id+"__"+response);
var fileId = file.id;
$("#"+fileId+" input").attr("id","file_id_"+fileId);
}
</script>
</head>
<body>
<h1>Uploadify Demo</h1>
<div id="queue"></div>
<input id="file_upload" type="file" multiple="true">
<input type="button" value="start upload..." οnclick="upload();">
<input type="button" value="stop upload..." οnclick="stop();">
</body>
</html>