webUploader图片上传

 资料图片(图片存储的位置以上传的为基础,后台查看放大图片为了显示可能会进行位置改变)
				    
				    	
选择图片

		
		
		

 资料图片(图片存储的位置以上传的为基础,后台查看放大图片为了显示可能会进行位置改变)
				    
				    	
选择图片
// 图片集 $("a[rel=group]").fancybox({ 'titlePosition' : 'over', 'cyclic' : true, 'titleFormat' : function(title, currentArray, currentIndex, currentOpts) { return '' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? '   ' + title : '') + ''; } }); }); function delImg(obj){ var result = confirm('确定删除此图片吗?'); if(result){ $(obj).parent().parent().parent().remove(); alert('删除成功!'); } return true; } @ResponseBody @RequestMapping(value="/upload") public Map upload(HttpServletRequest request, HttpServletResponse response) throws Exception{ String newFileName=""; String extName = ""; String responseStr=""; HashMap resultMap = new HashMap(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map fileMap = multipartRequest.getFileMap(); //String savePath = this.getServletConfig().getServletContext().getRealPath(""); //savePath = savePath + "/uploads/"; // 文件保存路径 ctxPath本地路径 String ctxPath=request.getSession().getServletContext().getRealPath("/")+"userfiles"; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); String ymd = sdf.format(new Date()); ctxPath += File.separator + ymd + File.separator; System.out.println("ctxpath="+ctxPath); // 创建文件夹 File file = new File(ctxPath); if (!file.exists()) { file.mkdirs(); } String fileName = null; for (Map.Entry entity : fileMap.entrySet()) { // 上传文件 MultipartFile mf = entity.getValue(); fileName = mf.getOriginalFilename();//获取原文件名 System.out.println("filename="+fileName); // 扩展名格式: if (fileName.lastIndexOf(".") >= 0) { extName = fileName.substring(fileName.lastIndexOf(".")); } newFileName = UUID.randomUUID().toString(); File uploadFile = new File(ctxPath + newFileName + extName); try { FileCopyUtils.copy(mf.getBytes(), uploadFile); responseStr="上传成功"; // 图片上传成功,生成缩略图 Thumbnails.of(uploadFile).size(226, 226).toFile(new File(ctxPath + newFileName+"_Min"+ extName)); resultMap.put("minPath", ymd +"/"+newFileName+"_Min"+extName); } catch (IOException e) { responseStr="上传失败"; e.printStackTrace(); } } resultMap.put("path", ymd +"/"+newFileName+extName); return resultMap; }


        
        
        
        
        

        

转载于:https://my.oschina.net/u/2481007/blog/886991

你可能感兴趣的:(json,javascript)