【广告项目】ftp+uploadify实现图片多图片上传预览

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>	<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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 20
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

女汉纸一枚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值