之前做过uploadify 2.x的文件上传,做这个项目的时候发现官网现在版本是3.2.1于是就做了一个demo。
前台代码如下(注意引入jquery):
<!DOCTYPE HTML >
<html>
<head>
<title>文件上传</title>
<%@include file="comm/comm.jsp" %>
<link rel="stylesheet" type="text/css" href="css/uploadify.css">
<script type="text/javascript" src="js/jquery.uploadify.min.js"></script>
<script >
$(document).ready(function() {
$("#file_upload").uploadify({
'buttonText' : '请选择',
'height' : 30,
'swf' : '/auth/js/uploadify.swf',
'uploader' : '/auth/uploadFile.html',
'width' : 120,
'auto':false,
'fileObjName' : 'file',
'onUploadSuccess' : function(file, data, response) {
alert( file.name + ' 上传成功! ');
}
});
});
</script>
</head>
<body>
<input type="file" name="fileName" id="file_upload" />
<a href="javascript:$('#file_upload').uploadify('upload', '*')">上传文件</a> | <a href="javascript:$('#file_upload').uploadify('stop')">停止上传!</a>
</body>
</html>
后台代码如下:
@RequestMapping(value="/uploadFile",method=RequestMethod.POST)
public void uploadFile(HttpServletResponse response,HttpServletRequest request,@RequestParam(value="file", required=false) MultipartFile file) throws IOException{
byte[] bytes = file.getBytes();
System.out.println(file.getOriginalFilename());
String uploadDir = request.getRealPath("/")+"upload";
File dirPath = new File(uploadDir);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
String sep = System.getProperty("file.separator");
File uploadedFile = new File(uploadDir + sep
+ file.getOriginalFilename());
FileCopyUtils.copy(bytes, uploadedFile);
msg = "true";
response.getWriter().write(msg);
}
分享到:
相关推荐
Uploadify3.2.1+Stream+PlUpload 三种批量上传控件(APS.NET) 。都测试通过了,方便大家学习
Uploadify-3.2.1 jQuery文件上传插件,使用uploadify组件可以实现异步无刷新多文件上传功能。
UpLoadify3.2.1版本上传插件的实现demo,你值得拥有.zip
导入到eclipse或者myeclipse可以直接使用,uploadify插件的所以属性和方法都有详细说明,可以去掉注释测试,是用servlet处理的文件上传
springMVC+uploadify上传图片。
uploadify + asp.net mvc实现文件上传功能
uploadify的demo,解决spring MVC上传配置冲突。保留springmvc的配置,修改controller中的代码。
uploadify + asp.net mvc实现文件上传功能
Uploadify是一个易集成的多文件上传解决方案,在手册翻译时,3.2版目前最新。作为一个jQuery插件,Uploadify不仅使用简单而且可定制性非常强。
此js解决jquery.uploadify.3.2.1 在IE9,IE10中 上传文件的按钮会无法点问题
文件包括Uploadify V3.2.1 上传文件报404 Not Found问题解决方法
修复uploadify3.2.1初始化基于当前页面和uploadify.swf发送多次请求
uploadify V3.2.1上传插件,并且内含 404 Not Found问题的解决方法哦!
MVC4下对话框中使用Uploadify上传多个文件
jquery上传插件uploadify+php完美实现强大的文件上传功能实例+程序_【PHP】.rar
jQuery Uploadify + Apache Fileupload异步上传文件示例
jquery uploadify3.1 与java 集成,包含有 页面,配置servlet web.xml 部署到tomcat中 ,即可使用。简单方便,页面中包含有 uploadify 3.1的 一些样式。可自行进行更改
基于Uploadify+jsp文件上传刷新,直接运行该程序就可以 了
struts2 +jquey uploadify3 2 实现多文件上传 可以运行的myeclipse工程 绝对好用 访问方式http: 127 0 0 1:8080 Struts2Uploadify upload jsp uploadify 使用说明: <a href "javascript:$ "#file ...