【广告项目】ftp+uploadify实现图片多图片上传预览
2017-09-19 18:22
639 查看
ftp上传结合uploadify,实现图片上传并预览:
上传js:
html部分:
后台上传部分:
效果图:
上传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)); }
效果图:
相关文章推荐
- jquery.uploadify插件实现图片上传和预览效果
- jquery.uploadify插件实现图片上传和预览效果
- 利用jquery.uploadify插件来实现图片上传和预览效果
- jquery.uploadify插件实现图片上传和预览效果
- jquery.uploadify插件实现图片上传和预览效果
- Jcrop+uploadify+php实现上传头像预览裁剪
- asp.net+uploadify实现图片上传图片
- 使用ThinkPHP+Uploadify实现图片上传功能
- 利用jsp+uploadify插件实现附件上传到ftp服务器的功能
- 基于jquery.uploadify实现图片上传
- 分离与继承的思想实现图片上传后的预览功能:ImageUploadView
- cfbd Javaweb项目图片上传实现预览
- struts2 +jquey uploadify3.2 实现多文件上传,可预览、删除、排序
- jquery.uploadView 实现图片预览上传功能
- struts2 +jquey uploadify3.2 实现多文件上传,可预览、删除、排序
- thinkphp+uploadify上传图片,实现缩略图浏览
- 分离与继承的思想实现图片上传后的预览功能:ImageUploadView
- 分离与继承的思想实现图片上传后的预览功能:ImageUploadView
- ajaxFileUpload实现图片的上传并预览
- jquery.uploadify插件实现上传和预览效果