uploadify的碎碎念 upload
uploadify是一个jquery插件,用来实现文件上传的功能。
20160724 看起来感觉挺麻烦的
一般会买一个html5版的。
html
<input id="custom_file_upload" type="file" name="Filedata" />
js
//关键是路径要设置正确
//总会发起请求:http://localhost:8080/jyxt/img/uploadify-cancel.png,不知道从哪发起的?
function inituploadimge(){
$('#custom_file_upload1').uploadify({
'swf' : path_t+'js/uploadify.swf',
//后台处理程序的URL
'uploader' : path_t+'manage/fileupload/',
'method' : "post",
'use_query_string': true,
'post_params': {
"hello" : encodeURI("你好,我是","utf-8"),
"baseurl" : "userfiles/images/linkimages/"
},
'cancelImage' : path_t+'images/cancel.png',
'buttonText' : '浏览',
'buttonImg' : path_t+'images/sel.png',
'queueID' : 'custom-queue1',
'fileTypeExts':'*.jpg;*.gif;*.png;',
'fileTypeDesc':'图片文件',
'removeCompleted': true,
'onSelectOnce' : function(event,data) {
$('#custom-queue1').text('文件上传中!');
},
'onUploadSuccess' : function(file, data, response) {
$('#custom-queue1').text('上传成功');
$('#picUrl').attr("value",data);
}
});
}
controller
//存储的路径设置比较麻烦
//1、savePath如何设置基础的路径?baseurl是传过来的,相对于webcontent的路径。
//2、保存时,会保存到tomcat下,应该保存在jyxt中呀?
//3、saveFile.getAbsolute()可以得到文件存储的路径。
//4、request.getServletPath() 是uploader的值
@RequestMapping(value = "/manage/fileupload/", method = RequestMethod.POST)
public void fileUpload(HttpServletRequest request,HttpServletResponse response) throws Exception {
//设置路径
String baseurl=request.getParameter("baseurl");
//路径有问题
String savePath = request.getSession().getServletContext().getRealPath("")+"/"+baseurl; DiskFileItemFactory fac = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fac); String filename=""; File f1 = new File(savePath);
if (!f1.exists()) {
f1.mkdirs();
}
List<FileItem> fileList = null;
fileList = (List<FileItem>) upload.parseRequest(request);
Iterator<FileItem> it = fileList.iterator(); String name = "";
String extName = "";
while (it.hasNext()) { FileItem item = it.next();
if (!item.isFormField()) {
name = item.getName();
if (name == null || name.trim().equals("")) {
continue;
}
if (name.lastIndexOf(".") >= 0) {
extName = name.substring(name.lastIndexOf("."));
}
Object[] test = {"gif","png","jpg","doc","docx","xls","xlsx","ppt","pptx","ptf","rar","zip",""};
if(!ArrayUtils.contains(test, extName.toLowerCase().substring(1)))
{
continue;
}
File file = null;
do {
name=DateUtil.getNowDateString();
filename=savePath + name + extName;
file = new File(filename);
} while (file.exists());
File saveFile = new File(filename);
try {
item.write(saveFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
response.getWriter().print(request.getContextPath()+"/userfiles/images/linkimages/"+name+extName);
}
以上代码是可以使用的。不过因为uploadify版本不同,文件路径不同,可能会有问题。只是借此记录一些关键的问题。
uploadify的碎碎念 upload的更多相关文章
- Linux碎碎念
在学习Linux过程中,有许多有用的小技巧.如果放在纸质的笔记本上,平时查阅会相当不方便.现在以一种“碎碎念”的方式,汇集整理在此,目前还不是很多,但随着学习.工作的深入,后续会陆陆续续添加更多的小技 ...
- 一些关于Linux入侵应急响应的碎碎念
近半年做了很多应急响应项目,针对黑客入侵.但疲于没有时间来总结一些常用的东西,寄希望用这篇博文分享一些安全工程师在处理应急响应时常见的套路,因为方面众多可能有些杂碎. 个人认为入侵响应的核心无外乎四个 ...
- 一个谷粉和3年的Google Reader重度使用者的碎碎念
2013-03-14 上午看到Andy Rubin辞去Android业务主管职务.由Chrome及应用高级副总裁继任的新闻,还在想这会给Android带来什么,中午刷微博的时候就挨了当头一棒:Goog ...
- Jerry的碎碎念:SAPUI5, Angular, React和Vue
去年我去一个国内客户现场时,曾经和他们IT部门的一位架构师聊到关于在SAP平台上进行UI应用的二次开发时,UI框架是选用UI5还是Vue这个话题. 我们代表SAP, 向客户推荐使用UI5是基于以下六点 ...
- 结对编程ending-我和洧洧的碎碎念
应该是第一次和队友分工合作去完成一个项目,其中也经历了跳进不少坑又被拉回来的过程,总体来说这对于我俩也的确是值得纪念的一次经历. 我的碎碎念时间…… 对比个人项目和结对编程项目二者需求,前者重在面对不 ...
- C语言 · 分分钟的碎碎念
算法提高 分分钟的碎碎念 时间限制:1.0s 内存限制:256.0MB 问题描述 以前有个孩子,他分分钟都在碎碎念.不过,他的念头之间是有因果关系的.他会在本子里记录每一个念头,并用 ...
- 最近关于Qt学习的一点碎碎念
最近关于Qt学习的一点碎碎念 一直在使用Qt,但是最近对Qt的认识更加多了一些.所以想把自己的一些想法记录下来. Qt最好的学习资料应该是官方的参考文档了.对Qt的每一个类都有非常详细的介绍.我做了一 ...
- Java实现 蓝桥杯VIP 算法提高 分分钟的碎碎念
算法提高 分分钟的碎碎念 时间限制:1.0s 内存限制:256.0MB 问题描述 以前有个孩子,他分分钟都在碎碎念.不过,他的念头之间是有因果关系的.他会在本子里记录每一个念头,并用箭头画出这个念头的 ...
- MySQL碎碎念
1. 如何修改Mysql的用户密码 mysql> update mysql.user set password=password('hello') where user='root'; mysq ...
随机推荐
- python 刷题必备
1.判断输入的数字是否是回文数: 学习内容:把数字转成字符串 1. def is_palindrome(n): n=str(n) m=n[::-1] return n==m 2. tmp_str = ...
- Extending Conductor
后端 导体提供了可插拔的后端.目前的实现使用Dynomite. 每个后端需要实现4个接口: //Store for workflow and task definitions com.netflix. ...
- Fiddler 捕获 nodejs 模拟的http请求
1.设置Fiddler Tools->Options-> Connections Allow remote computers to connect: 2.nodejs 请求有多种 2.1 ...
- electron 大体结构
1.Electron支持的平台: OS XWindowsLinux 2.一个标准的electron app包含的结构: Windows 或是 Linux中:electron/resources/app ...
- with as (转)
sql with as 用法(适用sqlserver,好像oracle也适用) Server 2005中提供了公用表表达式(CTE),使用CTE,可以使SQL语句的可维护性,同时,CTE要比表变量的效 ...
- overflow: scroll
overflow: scroll在安卓5.0的情况下,不论内容是否填满屏幕,都会强制解析出滚动条,所以最好是使用overflow: auto
- 前端基础之Bootstrap
1. 页面加载完之后才执行的JS代码 1. DOM方式 window.onload = function(){} 2. jQuery方式 ...
- 【SQL模板】三.插入/更新 数据模板TSQL
---Name: 插入/更新 数据模板.sql ---Purpose: 用于更新 数据库中 历史数据 或 插入 新数据 的脚本模板 ---Author: xx ---Time: 2015-12-18 ...
- Golang之http编程
Go原生支持http.import("net/http") Go的http服务性能和nginx比较接近 几行代码就可以实现一个web服务 服务端http package main ...
- 用户体验要好,App动画得这么做
以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 在用户体验设计方面,App动画的设计和添加,带给设计师无限的创造空间的同时,也成为设计师群体最具 ...