uploadify上传
2016-06-27 10:06
141 查看
一、上传按钮样式
1.1id="show_filebutton"是显示给用户操作按钮,id="filebutton"是flash上传按钮完成用户上传操作。id="show_filebutton"按钮样式不需要变,只需要将id="filebutton"按钮覆盖在id="show_filebutton"按钮上面就行了。
1.2uploadify会生成自己的html元素class="swfupload"
<html>
<body>
<head>
<style>
.swfupload{background:red;} //设置flash上传按钮背景颜色。可以看到按钮方便设置宽高等css属性
.swfupload{width: 120px;height: 35px; top: -35px;left: 50px;opacity:0;} //flash上传按钮覆盖美工提供过来的上传按钮,uploadify上传按钮本身就是透明不可见,这样方便我们覆盖在按钮上面达到效果
</style>
</head>
<button id="show_filebutton" type="button">导入数据文件</button>
<button type="button" id="filebutton"></button>
</body>
</html>
二、绑定上传按钮事件
$(document).ready(function(){
$("#filebutton").uploadify({
'swf' : '/plugin/uploader/uploadify.swf',
'uploader' : '/simple/upload.do',
'buttonClass' : 'upload',
'buttonText' : '',
'width': 'auto',
'queueID' : "upload_queue",
'auto' : false,
'fileObjName' : 'uploads',
'multi' : false, //多文件上传
'fileSizeLimit' : 2048 , //限制文件的大小,默认单位是KB
'uploadLimit' : 1,
'fileTypeDesc' : '支持资源格式:',
'fileTypeExts' : '*.xls;*.xlsx;',
'onUploadStart' : function(file){
$('#filebutton').uploadify("settings", "formData", {para:1});
},
'onUploadSuccess' : function(file, data, response) {
var uploadLimit = $("#filebutton").uploadify('settings', 'uploadLimit'); //get
$("#filebutton").uploadify('settings', 'uploadLimit', uploadLimit+1); //set
$("#downloadfilename").val(data);
}
});
});
java上传代码
public class Upload(){
public void uploadImage(){
UUID uuid = UUID.randomUUID();
String sysPath = getSession().getServletContext().getRealPath("");
File tempFile = new File(sysPath+"/upload/temp/");
if(!tempFile.exists()){
tempFile.mkdirs();
}
UploadFile upfile = getFile("image");
if(upfile != null){
File file = upfile.getFile();
String fileName = uuid+"_"+file.getName();
String filepath = "/upload/temp/"+fileName;
file.renameTo(new File(sysPath+filepath));
setAttr("filepath", filepath);
}
renderJson();
}
}
1.1id="show_filebutton"是显示给用户操作按钮,id="filebutton"是flash上传按钮完成用户上传操作。id="show_filebutton"按钮样式不需要变,只需要将id="filebutton"按钮覆盖在id="show_filebutton"按钮上面就行了。
1.2uploadify会生成自己的html元素class="swfupload"
<html>
<body>
<head>
<style>
.swfupload{background:red;} //设置flash上传按钮背景颜色。可以看到按钮方便设置宽高等css属性
.swfupload{width: 120px;height: 35px; top: -35px;left: 50px;opacity:0;} //flash上传按钮覆盖美工提供过来的上传按钮,uploadify上传按钮本身就是透明不可见,这样方便我们覆盖在按钮上面达到效果
</style>
</head>
<button id="show_filebutton" type="button">导入数据文件</button>
<button type="button" id="filebutton"></button>
</body>
</html>
二、绑定上传按钮事件
$(document).ready(function(){
$("#filebutton").uploadify({
'swf' : '/plugin/uploader/uploadify.swf',
'uploader' : '/simple/upload.do',
'buttonClass' : 'upload',
'buttonText' : '',
'width': 'auto',
'queueID' : "upload_queue",
'auto' : false,
'fileObjName' : 'uploads',
'multi' : false, //多文件上传
'fileSizeLimit' : 2048 , //限制文件的大小,默认单位是KB
'uploadLimit' : 1,
'fileTypeDesc' : '支持资源格式:',
'fileTypeExts' : '*.xls;*.xlsx;',
'onUploadStart' : function(file){
$('#filebutton').uploadify("settings", "formData", {para:1});
},
'onUploadSuccess' : function(file, data, response) {
var uploadLimit = $("#filebutton").uploadify('settings', 'uploadLimit'); //get
$("#filebutton").uploadify('settings', 'uploadLimit', uploadLimit+1); //set
$("#downloadfilename").val(data);
}
});
});
java上传代码
public class Upload(){
public void uploadImage(){
UUID uuid = UUID.randomUUID();
String sysPath = getSession().getServletContext().getRealPath("");
File tempFile = new File(sysPath+"/upload/temp/");
if(!tempFile.exists()){
tempFile.mkdirs();
}
UploadFile upfile = getFile("image");
if(upfile != null){
File file = upfile.getFile();
String fileName = uuid+"_"+file.getName();
String filepath = "/upload/temp/"+fileName;
file.renameTo(new File(sysPath+filepath));
setAttr("filepath", filepath);
}
renderJson();
}
}
相关文章推荐
- 修改PullToRefresh中上拉下拉的图标和文字
- HDU 4960 (区间DP)
- 浏览器阻止新窗口(window.open或新窗的form提交)
- 对MTK平台的一些认识
- input框限制只能输入正整数、字母、小数、汉字
- 使用DotNetBarcode制作基本常用条码
- 当xcode里点运行出现treating unicode character as whites
- 一些小函数
- LINUX-vbird
- Java基础之异常Exception(5)---小练习
- 前端同学大福利,最全的面试题目整理
- MFC-控件-标签-设置背景透明
- 敏捷测试模式之Scrum及其实践
- Java中的拆箱和装箱
- iOS 纯代码控件布局
- timeout connect 10000 # default 10 second time out if a backend is not found
- MyEclipse + Maven开发Web工程的详细配置过程
- 解析ABP框架中的数据传输对象与应用服务
- 统计字符串中重复的字符个数及字符
- timeout connect 10000 # default 10 second time out if a backend is not found