【广告项目】ftp+uploadify实现图片多图片上传预览
来源:互联网 发布:php看什么书 编辑:程序博客网 时间:2024/05/22 10:42
ftp上传结合uploadify,实现图片上传并预览:
上传js:
$(function(){$('#appendFile1').delegate('.mailListDel1', 'click' ,function(){ var _this = $(this); var el = _this.parent().remove(); })var definedData = [];definedData.fileTypeExts = "*.png;*.jpeg;*.gif;*.jpg"; $("#uploadAttach1").uploadify({ 'height' : 20,//设置浏览按钮的高度 'width' : 80, 'buttonText' : '添加图片', 'swf' : '${pageContext.request.contextPath}/plugin/uploadify.swf', 'uploader' : '${pageContext.request.contextPath}/daily/uploadAttach', 'auto' : true, 'multi' : true,//设置为true时可以上传多个文件。 'removeCompleted': true, 'cancelImg' : '${pageContext.request.contextPath}/plugin/cancel.png', 'fileTypeExts' : definedData.fileTypeExts, 'fileSizeLimit' : '100MB', 'fileObjName' : 'file1', 'sizeLimit': '99999999999', 'onUploadSuccess':function(file,data,response){ var jsonData = JSON.parse(data); $.each(jsonData,function(i,v){ $("#uploadAttach-queue1").append( "<div style='float:left;text-align:center; padding: 0 5px;'>"+"<img src='"+v.attachPath+"' alt='' style='width: 130px;height:100px'/><a href='#' class='mailListDel1 ' style='color:#929292;display:block;'> 删除 </a><input type='hidden' name='path1' value=" + v.attachPath + "><input type='hidden' name='attachNmaeArr1' value=" + v.attachName + "></div>" ) }) }, //加上此句会重写onSelectError方法【需要重写的事件】 'overrideEvents': ['onSelectError', 'onDialogClose'], //返回一个错误,选择文件的时候触发 'onSelectError':function(file, errorCode, errorMsg){ switch(errorCode) { case -110: alert("文件 ["+file.name+"] 大小超出系统限制的" + jQuery('#uploadAttach1').uploadify('settings', 'fileSizeLimit') + "大小!"); break; case -120: alert("文件 ["+file.name+"] 大小异常!"); break; case -130: alert("文件 ["+file.name+"] 类型不正确!"); break; } }, }); $(".cancle").hide();})
html部分:
<div class="full"> <span class="formContentName lf">刊物信息:</span><div id="appendFile1" style=" box-sizing: border-box;padding-left:135px"><div><input type="file" id="uploadAttach1" name="files1" /><div id="uploadAttach-queue1" class="uploadify-queue1"></div></div></div></div>
后台上传部分:
@RequestMapping("uploadAttach") public void uploadAttach(final HttpSession session,HttpServletRequest request, HttpServletResponse response) throws IOException{List<TaMail> list = new ArrayList<TaMail>(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); String fileName = null; for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { //获得源文件,上传到服务器,返回文件名称和路径; MultipartFile mf = entity.getValue(); fileName = mf.getOriginalFilename();//获取原文件名 if(fileName.length() > 0){TaMail mail = new TaMail();Date now = new Date();SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");String filePath = dateFormat.format(now);String newName = UUID.randomUUID().toString();String subfix = fileName.substring(fileName.lastIndexOf("."));Boolean flag = FtpUtil.uploadFile(ftpIp, ftpPort, ftpUserName, ftpPassword, ftpRemotePath,filePath, newName+subfix, mf.getInputStream());final String attachPath= new String(httpUrl+filePath+"/"+newName+subfix);mail.setAttachName(fileName);mail.setAttachPath(attachPath);list.add(mail);} } response.setCharacterEncoding("UTF-8"); response.setContentType("application/json; charset=utf-8"); response.getWriter().write(JsonUtils.objectToJson(list)); }
效果图:
阅读全文
1 0
- 【广告项目】ftp+uploadify实现图片多图片上传预览
- uploadify插件实现多个图片上传并预览
- Uploadify 控件上传图片 + 预览
- jquery.uploadify插件实现图片上传和预览效果
- jquery.uploadify插件实现图片上传和预览效果
- jquery.uploadify插件实现图片上传和预览效果
- jquery.uploadify插件实现图片上传和预览效果
- Uploadify v3.2.1 上传图片并预览
- Uploadify v3.2.1 上传图片并预览
- uploadify上传多图片
- Javaweb项目图片上传实现预览
- 实现图片上传预览
- 上传图片实现预览
- uploadify struts2实现图片上传
- 上传图片,实现图片预览
- 上传图片实现图片预览
- asp.net+uploadify实现图片上传图片
- 利用JQuery上传插件Uploadify实现图片上传MongoDB并预览
- lvs、haproxy、nginx 负载均衡的比较分析
- 关于linux-centos-samba用法
- CentOSRedhat系统的软件仓库配置方法
- 如何快速成为数据分析师
- 网站点击流数据分析
- 【广告项目】ftp+uploadify实现图片多图片上传预览
- I2C总线浅谈之(二)---时序
- 序号互换
- 如何查看apk包里的targetSdkVersion
- recyclerView列表使用Timer定时器复用错乱的问题
- 51nod 1060 最复杂的数
- CXF之jaxws:endpoint对spring bean的引用
- codeforces/2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (B)
- 使用idea 搭建ssm+maven+logback项目