图片多上传
来源:互联网 发布:js购物车结算页面 编辑:程序博客网 时间:2024/06/05 15:06
前台js
$("#imgUpload").change(function(e){ for(var i=0;i<e.target.files.length;i++){ var file = e.target.files.item(i); if(!(/^image\/.*$/i.test(file.type))) { continue; } Goodsfiles.push(file) } ImgUpload(Goodsfiles,purl+'helpbuyUnfinished.dh?key=uploadImg"); })function ImgUpload(files,url){ var formdata = new FormData(); if(files.length==0){ return ; } $.showPreloader($.i18n.prop('uploading')); $.each(files, function(k, v){ formdata.append("fileList"+k, v); }); $.ajax({ url : url, type : 'POST', data : formdata, processData : false, contentType : false, dataType : 'json', success : function(data) { $.hidePreloader(); }, error : function(responseStr) { } }); }
后台接收
String uploadImg = ""; String url = request.getScheme()+"://"; url+=request.getHeader("host"); datefolder = DateUtility.getYear() + "/" + DateUtility.getMonth() + "/" + DateUtility.getDay()+"/"; String webParentPath = new File(request.getSession().getServletContext().getRealPath("/")).getParent(); String realPath = webParentPath + fileFolder; System.out.println(realPath); File file = new File(realPath); if (!file.isDirectory()) { file.mkdirs(); } DiskFileItemFactory fac = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(fac); upload.setHeaderEncoding("UTF-8"); List<?> fileList = upload.parseRequest(request); Iterator<?> it = fileList.iterator(); while (it.hasNext()) { Object obit = it.next(); if(obit instanceof DiskFileItem){ DiskFileItem item = (DiskFileItem) obit; String fileName = UUID.randomUUID().toString().replace("-", "");; BufferedInputStream imgin = new BufferedInputStream(item.getInputStream()); BufferedImage sourceImg =ImageIO.read(imgin); //图片等宽 比例压缩 400px int width = sourceImg.getWidth(); int height = sourceImg.getHeight(); BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(new File(realPath+fileName))); int h = (int) (height * 400 / width); BufferedImage image = new BufferedImage(400, h,BufferedImage.TYPE_INT_RGB ); image.getGraphics().drawImage(sourceImg, 0, 0, 400, h, null); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outStream); encoder.encode(image); outStream.close(); imgin.close(); } }
0 0
- 多图片上传
- webwork 多图片上传
- Struts 多图片上传
- 多图片上传实现
- ASP 多图片上传
- 多图片上传
- 多张图片上传
- 多图片上传
- xutils上传多图片
- Yii多图片上传
- uploadify上传多图片
- iOS多图片上传
- IOS:多图片上传
- ios多图片上传
- springMVC多图片上传
- 多图片上传
- 多图片批量上传
- springmvc上传多图片
- spring+Mybatis+Ehcache整合(Ehcachec参数说明XML配置)
- 比较常用的处理字符串的函数
- SEO快速排名算法独家揭秘
- eclipse快捷键
- 微博头视图下拉放大效果 tableview头视图下拉放大效果
- 图片多上传
- HDU 5728 PowMod (欧拉函数+指数循环节)
- jQuery源码分析研究学习笔记-jQuery.clean()(七)
- 互联网行业周报:ORACLE以93亿美元高价收购NETSUITE火拼云计算
- 顺序链表的实现
- linux/ubuntu 端口开放
- 关于android输入法问题
- ubuntu 10.04下设置pythonpath
- 文件系统