├── picture-server ├── src │ └── main │ │ ├── webapp │ │ ├── index.html │ │ ├── WEB-INF │ │ │ ├── ftl │ │ │ │ ├── footer.ftl │ │ │ │ ├── sidebar.ftl │ │ │ │ ├── header.ftl │ │ │ │ ├── modifypasswordform.ftl │ │ │ │ ├── main.ftl │ │ │ │ ├── upload.ftl │ │ │ │ └── view.ftl │ │ │ ├── springmvc-servlet.xml │ │ │ └── web.xml │ │ ├── result.jsp │ │ └── scripts │ │ │ ├── custom │ │ │ ├── view.js │ │ │ ├── upload.js │ │ │ └── cl.js │ │ │ └── plugin │ │ │ └── ajaxfileupload.js │ │ ├── java │ │ └── com │ │ │ └── cl │ │ │ └── picture │ │ │ ├── utils │ │ │ ├── ConstantUtil.java │ │ │ ├── SessionUtil.java │ │ │ ├── ConfigUtil.java │ │ │ ├── SpringContextHolder.java │ │ │ ├── JsonUtil.java │ │ │ ├── ImageUtil.java │ │ │ ├── ReflectionUtil.java │ │ │ └── StringUtil.java │ │ │ ├── interceptor │ │ │ └── PictureInterceptor.java │ │ │ └── controller │ │ │ ├── IndexController.java │ │ │ └── OpController.java │ │ └── resources │ │ ├── config.properties │ │ ├── cas-picture.xml │ │ ├── applicationContext-dubbo.xml │ │ ├── log4j.xml │ │ ├── applicationContext.xml │ │ └── log4j.dtd └── pom.xml ├── .gitignore ├── create_picture.sql ├── README.md └── pom.xml /picture-server/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /picture-server/src/main/webapp/WEB-INF/ftl/footer.ftl: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /picture-server/src/main/webapp/result.jsp: -------------------------------------------------------------------------------- 1 | <%@ page pageEncoding="UTF-8" %> 2 | <%@ page contentType="text/html; charset=UTF-8" %> 3 | <% 4 | String s = request.getParameter("result"); 5 | if(s!=null) 6 | { 7 | //s=java.net.URLDecoder.decode(s,"UTF-8"); 8 | //s=new String(s.getBytes("ISO-8859-1")); 9 | out.print(s); 10 | } else { 11 | out.print("{result:'fail',message:'没有返回数据'}"); 12 | } 13 | %> -------------------------------------------------------------------------------- /picture-server/src/main/java/com/cl/picture/utils/ConstantUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.picture.utils; 2 | 3 | public class ConstantUtil { 4 | 5 | public static final String Fail = "fail"; 6 | 7 | public static final String Success = "success"; 8 | 9 | public static final String Exists = "exists"; 10 | 11 | public static final String EmptyJsonObject = "{}"; 12 | 13 | public static final String DefaultMd5Password = "63a9f0ea7bb98050796b649e85481845"; //root 14 | } 15 | -------------------------------------------------------------------------------- /picture-server/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | #CAS authentication address 2 | cas.server.url=http://127.0.0.1:8080/cas 3 | cas.service.url=http://127.0.0.1:10004/picture-server 4 | 5 | #Base Path 6 | web.basepath=http://127.0.0.1:10004/picture-server 7 | #Inc File Path 8 | inc.basepath=http://127.0.0.1/privilege_inc 9 | #Pic File Path 10 | pic.basepath=http://127.0.0.1/privilege_pic 11 | 12 | #ZooKeeper 13 | dubbo.registry.address=127.0.0.1:2181 14 | dubbo.registry.address.client=127.0.0.1:2181 15 | 16 | #图片存储位置 17 | picture.location=/work -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # Ignore all logfiles and tempfiles. 15 | .project 16 | /*/.project 17 | 18 | .classpath 19 | /*/.classpath 20 | 21 | .settings 22 | /*/.settings 23 | /*/.settings/* 24 | 25 | target 26 | /*/target 27 | /*/target/* 28 | 29 | .DS_Store 30 | 31 | .svn 32 | .svn/* 33 | 34 | .idea 35 | .idea/* 36 | 37 | Thumbs.db 38 | 39 | *.log 40 | *.out 41 | -------------------------------------------------------------------------------- /create_picture.sql: -------------------------------------------------------------------------------- 1 | delete from `p_module` where name='图片中心'; 2 | INSERT INTO `p_module`(id,name,flag,url,sort_no,create_person,create_date,update_person,update_date) 3 | VALUES 4 | (2,'图片中心','pi','http://127.0.0.1:10004/picture-server',20,'system',NOW(),'system',NOW()) 5 | ; 6 | 7 | 8 | delete from `p_resource` where module_flag='pi'; 9 | INSERT INTO `p_resource`(id,name,url,remark,parent_id,structure,sort_no,module_flag,create_person,create_date,update_person,update_date) 10 | VALUES 11 | (5,'图片浏览','/controller/view.do','',0,'s-1',1,'pi','system',NOW(),'system',NOW()), 12 | (6,'图片上传','/controller/upload.do','',0,'s-2',2,'pi','system',NOW(),'system',NOW()) 13 | ; -------------------------------------------------------------------------------- /picture-server/src/main/webapp/WEB-INF/ftl/sidebar.ftl: -------------------------------------------------------------------------------- 1 | 2 |
3 | 24 |
25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cl-picture 2 | ================== 3 | 4 | 通用图片管理系统 5 | 6 | 7 | 一、前置项目依赖 8 | 9 | https://github.com/pumadong/cl-privilege 10 | 11 | 二、项目说明 12 | 13 | 图片管理,用于部署在一台单独的图片服务器,接收商品图片的上传,作为CDN服务器的源站,并提供简单的图片浏览、删除、上传功能。 14 | 15 | 图片管理主要是商品的图片管理,所以涉及的一些规则验证,基本是商品相关的。 16 | 17 | 图片名称规则:商品编号_01_图片类型.jpg,商品编号:8-10位数字,01:商品序号,代表第一个位置,图片类型:o、l、m、s、t、b,第一个位置的图片切一个c。 18 | 19 | o(1000*1000),original,原始图片 20 | 21 | l(480*480),large,大图 22 | 23 | m(240*240),middle,中图 24 | 25 | s(160*160),small,小图 26 | 27 | t(60*60),tiny,微小图 28 | 29 | b(750*750),baby,宝贝描述图 30 | 31 | c(40*40),color,颜色图,单品页展示用 32 | 33 | 三、Jquery插件 34 | 35 | Jquery Ajax File Uploader : http://www.phpletter.com/DOWNLOAD/ 36 | 37 | 因为Ajax是不能跨域的,这个插件的作用是生成一个隐藏的Form来提交,并定义一个本域的jsp文件用于接收处理结果。 38 | 39 | 对于文件上传来说,应该实现选择多个目录,批量上传,这个是B/S结构的商品管理要考虑的技术问题。 40 | 41 | 四、其他 42 | 43 | 44 | 图片管理,可以有自动切图功能,直接输入包含尺寸的url,自动切出需要的尺寸。 45 | 46 | 图片越来越大,单台机器不能满足要求时,可以引入Gearman之类的分布式图片管理框架。 -------------------------------------------------------------------------------- /picture-server/src/main/java/com/cl/picture/utils/SessionUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.picture.utils; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpSession; 5 | 6 | import com.cl.privilege.model.User; 7 | 8 | 9 | public class SessionUtil { 10 | 11 | /** 12 | * 系统登录用户名 13 | */ 14 | public static final String SessionSystemLoginUserName = "SessionSystemLoginUserName"; 15 | 16 | /** 17 | * 清空session 18 | */ 19 | public static final void clearSession(HttpServletRequest request) 20 | { 21 | HttpSession session = request.getSession(); 22 | 23 | session.removeAttribute(SessionUtil.SessionSystemLoginUserName); 24 | 25 | session.invalidate();//非必须,单点登出接收到服务器消息时,会自动销毁session 26 | } 27 | 28 | /** 29 | * 返回session中的用户对象 30 | * @param request 31 | * @return 32 | */ 33 | public static final User getSessionUser(HttpServletRequest request) 34 | { 35 | return (User) request.getSession().getAttribute(SessionUtil.SessionSystemLoginUserName); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | cl 4 | picture 5 | 1.0.0-SNAPSHOT 6 | pom 7 | picture 8 | http://maven.apache.org 9 | 10 | 11 | picture-server 12 | 13 | 14 | 15 | 16 | junit 17 | junit 18 | 4.11 19 | test 20 | 21 | 22 | 23 | 24 | 25 | releases 26 | Cl Releases 27 | http://192.168.1.11:8081/nexus/content/repositories/releases 28 | 29 | 30 | snapshots 31 | Cl Snapshots 32 | http://192.168.1.11:8081/nexus/content/repositories/snapshots 33 | 34 | 35 | -------------------------------------------------------------------------------- /picture-server/src/main/java/com/cl/picture/utils/ConfigUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.picture.utils; 2 | 3 | import java.io.File; 4 | 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class ConfigUtil { 10 | 11 | private @Value("${cas.server.url}")String casServerUrl; 12 | private @Value("${cas.service.url}")String casServiceUrl; 13 | private @Value("${web.basepath}")String basePath; 14 | private @Value("${inc.basepath}")String incBasePath; 15 | private @Value("${pic.basepath}")String picBasePath; 16 | private @Value("${picture.location}")String pictureLocation; 17 | 18 | public String getCasServerUrl() { 19 | return casServerUrl; 20 | } 21 | 22 | public String getCasServiceUrl() { 23 | return casServiceUrl; 24 | } 25 | 26 | public String getBasePath() { 27 | return basePath; 28 | } 29 | 30 | public String getIncBasePath() { 31 | return incBasePath; 32 | } 33 | 34 | public String getPicBasePath() { 35 | return picBasePath; 36 | } 37 | 38 | public String getPictureLocation() { 39 | return pictureLocation + File.separator + "pics" + File.separator + "c" + File.separator; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /picture-server/src/main/resources/cas-picture.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /picture-server/src/main/resources/applicationContext-dubbo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Dubbo provider配置 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | -------------------------------------------------------------------------------- /picture-server/src/main/java/com/cl/picture/utils/SpringContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.cl.picture.utils; 2 | 3 | 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | 7 | public class SpringContextHolder implements ApplicationContextAware { 8 | 9 | private static ApplicationContext applicationContext; 10 | 11 | public void setApplicationContext(ApplicationContext ac) 12 | { 13 | applicationContext = ac; 14 | } 15 | 16 | public static ApplicationContext getApplicationContext() 17 | { 18 | checkApplicationContext(); 19 | return applicationContext; 20 | } 21 | 22 | @SuppressWarnings("unchecked") 23 | public static T getBean(String name) 24 | { 25 | checkApplicationContext(); 26 | return (T) applicationContext.getBean(name); 27 | } 28 | 29 | public static T getBean(Class requiredType) 30 | { 31 | checkApplicationContext(); 32 | return applicationContext.getBean(requiredType); 33 | } 34 | 35 | public static void cleanApplicationContext() 36 | { 37 | applicationContext = null; 38 | } 39 | 40 | private static void checkApplicationContext() { 41 | if (applicationContext == null) 42 | throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder"); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /picture-server/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /picture-server/src/main/java/com/cl/picture/interceptor/PictureInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.cl.picture.interceptor; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.jasig.cas.client.util.AssertionHolder; 7 | import org.jasig.cas.client.validation.Assertion; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 10 | 11 | import com.cl.picture.utils.ConfigUtil; 12 | import com.cl.picture.utils.SessionUtil; 13 | import com.cl.privilege.api.IPrivilegeBaseApiService; 14 | import com.cl.privilege.model.User; 15 | 16 | 17 | /** 18 | * 拦截指定path,进行权限验证,及用户的本地session过期后,重新进行赋值 19 | */ 20 | public class PictureInterceptor extends HandlerInterceptorAdapter { 21 | 22 | @Autowired 23 | private ConfigUtil configUtil; 24 | @Autowired 25 | private IPrivilegeBaseApiService privilegeBaseApiService; 26 | 27 | @Override 28 | public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception { 29 | 30 | Assertion assertion=AssertionHolder.getAssertion(); 31 | 32 | //实际cas-client-core中org.jasig.cas.client.authentication.AuthenticationFilter已经进行了单点登录认证,这里主要是为了获得用户信息 33 | if(assertion==null 34 | || assertion.getPrincipal()==null 35 | || assertion.getPrincipal().getName()==null) 36 | { 37 | //没有登录,跳转到没有登录页面 38 | response.sendRedirect(configUtil.getCasServerUrl()); 39 | return false; 40 | } 41 | 42 | User user = SessionUtil.getSessionUser(request); 43 | 44 | if(user == null) 45 | { 46 | //存储Session:用户登录名 47 | user = privilegeBaseApiService.getUserByUsername(assertion.getPrincipal().getName()); 48 | request.getSession().setAttribute(SessionUtil.SessionSystemLoginUserName,user); 49 | } 50 | 51 | //判断权限,没有权限,进入没有权限页面 52 | 53 | return true; 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /picture-server/src/main/webapp/WEB-INF/ftl/header.ftl: -------------------------------------------------------------------------------- 1 | 2 | 50 | -------------------------------------------------------------------------------- /picture-server/src/main/webapp/WEB-INF/ftl/modifypasswordform.ftl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 49 | 50 | 54 | 55 | -------------------------------------------------------------------------------- /picture-server/src/main/java/com/cl/picture/utils/JsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.picture.utils; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.Collection; 5 | 6 | 7 | public class JsonUtil { 8 | 9 | public static StringBuffer convertObj2json(Collection cs) { 10 | 11 | StringBuffer sbf = new StringBuffer(); 12 | 13 | if (null == cs || 0 == cs.toArray().length){ 14 | 15 | return sbf.append("[").append("]"); 16 | } 17 | 18 | Object[] ls = cs.toArray(); 19 | int size = ls.length; 20 | 21 | sbf.append("["); 22 | if (0 == size) 23 | return new StringBuffer("[]"); 24 | for (int k = 0; k < size; k++) { 25 | Object o = ls[k]; 26 | 27 | sbf.append(convertObj2json(o)); 28 | 29 | if (k < size - 1) 30 | sbf.append(", "); 31 | } 32 | 33 | return sbf.append("]"); 34 | 35 | } 36 | 37 | public static StringBuffer convertObj2json(Object o) { 38 | 39 | StringBuffer sbf = new StringBuffer(); 40 | if (null == o) 41 | return sbf; 42 | 43 | sbf.append("{"); 44 | Class classType = o.getClass(); 45 | Field[] fields = classType.getDeclaredFields(); 46 | 47 | int length = fields.length; 48 | 49 | for (int i = 0; i < length; i++) { 50 | 51 | String fieldName = fields[i].getName(); 52 | Class clazzType = fields[i].getType(); 53 | Package package1 = clazzType.getPackage(); 54 | Object fo = ReflectionUtil.getFieldValue(o, fieldName); 55 | 56 | if (!(fo instanceof Collection) 57 | && (clazzType.isPrimitive() || null == package1 58 | || package1.getName().equals("java.lang") || package1 59 | .getName().equals("java.util"))) { 60 | sbf.append("\"").append(fieldName).append("\":\"").append(fo) 61 | .append("\""); 62 | } else if (!(fo instanceof Collection)) { 63 | sbf.append("\"").append(fieldName).append("\":").append( 64 | convertObj2json(fo)); 65 | } 66 | 67 | if (fo instanceof Collection) { 68 | 69 | sbf.append("\"").append(fieldName).append("\":").append( 70 | convertObj2json((Collection) fo)); 71 | 72 | } 73 | 74 | if (i < length - 1) 75 | sbf.append(", "); 76 | 77 | } 78 | 79 | return sbf.append("}"); 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /picture-server/src/main/webapp/scripts/custom/view.js: -------------------------------------------------------------------------------- 1 | var View = function () { 2 | return { 3 | //检查目录文件是否上传完整 4 | check: function() { 5 | var regNo = /^\d{8,10}$/; 6 | if($("#year").val()=="") 7 | { 8 | View.show(); 9 | $("#checkResult").text("请选择年份!"); 10 | return false; 11 | } 12 | if($("#month").val()=="") 13 | { 14 | View.show(); 15 | $("#checkResult").text("请选择月份!"); 16 | return false; 17 | } 18 | if($("#no").val() == "") 19 | { 20 | View.show(); 21 | $("#checkResult").text("请填写商品编号!"); 22 | return false; 23 | } 24 | if(!regNo.test($("#no").val())) 25 | { 26 | View.show(); 27 | $("#checkResult").text("商品编号必须为8-10位的数字!"); 28 | return false; 29 | } 30 | return true; 31 | }, 32 | search: function() { 33 | if(!View.check()) 34 | { 35 | return; 36 | } 37 | View.hide(); 38 | //document.form[0].submit(); 39 | $("#form_cl").submit(); 40 | }, 41 | delete: function() { 42 | if(!View.check()) 43 | { 44 | return; 45 | } 46 | View.hide(); 47 | $("#loading").show(); 48 | $.ajaxFileUpload 49 | ( 50 | { 51 | url:$("#url_request").val(), 52 | secureuri:false, 53 | fileElementId:'deleteFile', 54 | dataType: 'json', 55 | data: {//加入的文本参数 56 | "dt": $("#year").val() + $("#month").val(), 57 | "no": $("#no").val(), 58 | "url": $("#url_response").val() 59 | }, 60 | beforeSend:function() 61 | { 62 | $("#loading").show(); 63 | }, 64 | complete:function() 65 | { 66 | $("#loading").hide(); 67 | }, 68 | success: function (data, status) 69 | { 70 | if(typeof(data.result) != 'undefined') 71 | { 72 | View.show(); 73 | $("#checkResult").text(data.message); 74 | } 75 | }, 76 | error: function (data, status, e) 77 | { 78 | alert(e); 79 | } 80 | } 81 | ); 82 | }, 83 | refreshCDN: function() { 84 | View.show(); 85 | $("#checkResult").text("调用CDN方的接口,强迫图片刷新!"); 86 | }, 87 | show: function() { 88 | $("#checkResult").show(); 89 | }, 90 | hide: function() { 91 | $("#checkResult").hide(); 92 | } 93 | } 94 | }(); 95 | -------------------------------------------------------------------------------- /picture-server/src/main/webapp/scripts/custom/upload.js: -------------------------------------------------------------------------------- 1 | var Upload = function () { 2 | return { 3 | //检查目录文件是否上传完整 4 | check: function() { 5 | var regNo = /^\d{8,10}$/; 6 | if($("#year").val()=="") 7 | { 8 | Upload.show(); 9 | $("#checkResult").text("请选择年份!"); 10 | return false; 11 | } 12 | if($("#month").val()=="") 13 | { 14 | Upload.show(); 15 | $("#checkResult").text("请选择月份!"); 16 | return false; 17 | } 18 | if($("#no").val() == "") 19 | { 20 | Upload.show(); 21 | $("#checkResult").text("请填写商品编号!"); 22 | return false; 23 | } 24 | if(!regNo.test($("#no").val())) 25 | { 26 | Upload.show(); 27 | $("#checkResult").text("商品编号必须为8-10位的数字!"); 28 | return false; 29 | } 30 | var uf = $("#uploadFile").val(); 31 | uf = uf.substring(uf.lastIndexOf("\\")+1); 32 | var regPic = /^\d{8,10}_[0,1]{1}\d{1}_[b,o]{1}.\w+$/; //图片格式必须为:12345678_01_o.png样式 33 | if(!regPic.test(uf)) 34 | { 35 | Upload.show(); 36 | $("#checkResult").text("图片格式不正确!"); 37 | return false; 38 | } 39 | if($("#no").val() != uf.substring(0,uf.indexOf("_"))) 40 | { 41 | Upload.show(); 42 | $("#checkResult").text("商品编号和图片名称不一致!"); 43 | return false; 44 | } 45 | return true; 46 | }, 47 | upload: function() { 48 | if(!Upload.check()) 49 | { 50 | return; 51 | } 52 | Upload.hide(); 53 | $("#loading").show(); 54 | $.ajaxFileUpload 55 | ( 56 | { 57 | url:$("#url_request").val(), 58 | secureuri:false, 59 | fileElementId:'uploadFile', 60 | dataType: 'json', 61 | data: {//加入的文本参数 62 | "dt": $("#year").val() + $("#month").val(), 63 | "no": $("#no").val(), 64 | "url": $("#url_response").val() 65 | }, 66 | beforeSend:function() 67 | { 68 | $("#loading").show(); 69 | }, 70 | complete:function() 71 | { 72 | $("#loading").hide(); 73 | }, 74 | success: function (data, status) 75 | { 76 | if(typeof(data.result) != 'undefined') 77 | { 78 | Upload.show(); 79 | $("#checkResult").text(data.message); 80 | } 81 | }, 82 | error: function (data, status, e) 83 | { 84 | alert(e); 85 | } 86 | } 87 | ); 88 | }, 89 | show: function() { 90 | $("#checkResult").show(); 91 | }, 92 | hide: function() { 93 | $("#checkResult").hide(); 94 | } 95 | } 96 | }(); 97 | -------------------------------------------------------------------------------- /picture-server/src/main/webapp/WEB-INF/springmvc-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | text/plain;charset=UTF-8 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /picture-server/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | Cl Picture Manage Server 7 | 8 | webAppRootKey 9 | picture-server.root 10 | 11 | 12 | contextConfigLocation 13 | 14 | classpath*:/applicationContext*.xml 15 | classpath*:/cas-picture.xml 16 | 17 | 18 | 19 | log4jConfigLocation 20 | /WEB-INF/classes/log4j.xml 21 | 22 | 23 | spring.profiles.default 24 | dev 25 | 26 | 27 | 28 | 29 | encodingFilter 30 | org.springframework.web.filter.CharacterEncodingFilter 31 | 32 | encoding 33 | UTF-8 34 | 35 | 36 | forceEncoding 37 | true 38 | 39 | 40 | 41 | encodingFilter 42 | *.do 43 | 44 | 45 | 46 | 47 | 48 | org.jasig.cas.client.session.SingleSignOutHttpSessionListener 49 | 50 | 51 | CAS Single Sign Out Filter 52 | org.jasig.cas.client.session.SingleSignOutFilter 53 | 54 | 55 | CAS Single Sign Out Filter 56 | /controller/* 57 | 58 | 59 | 60 | 61 | 62 | CAS Authentication Filter 63 | org.springframework.web.filter.DelegatingFilterProxy 64 | 65 | targetBeanName 66 | casAuthenticationFilter 67 | 68 | 69 | 70 | CAS Authentication Filter 71 | /controller/* 72 | 73 | 74 | CAS Validation Filter 75 | org.springframework.web.filter.DelegatingFilterProxy 76 | 77 | targetBeanName 78 | casTicketValidationFilter 79 | 80 | 81 | 82 | CAS Validation Filter 83 | /controller/* 84 | 85 | 86 | 87 | 88 | CAS Assertion Thread Local Filter 89 | org.jasig.cas.client.util.AssertionThreadLocalFilter 90 | 91 | 92 | CAS Assertion Thread Local Filter 93 | /controller/* 94 | 95 | 96 | 97 | 98 | 99 | org.springframework.web.context.ContextLoaderListener 100 | 101 | 102 | 103 | springmvc 104 | org.springframework.web.servlet.DispatcherServlet 105 | 1 106 | 107 | 108 | springmvc 109 | *.do 110 | 111 | 112 | springmvc 113 | *.op 114 | 115 | 116 | 117 | 118 | csv 119 | application/octet-stream 120 | 121 | 122 | 123 | index.html 124 | index.jsp 125 | 126 | 127 | -------------------------------------------------------------------------------- /picture-server/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | Spring公共配置 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | classpath*:/config.properties 48 | 49 | file:/d:/conf/cl/picture/*.properties 50 | 51 | file:/etc/conf/cl/picture/*.properties 52 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 62 | 63 | 64 | 0 65 | zh_CN 66 | UTF-8 67 | UTF-8 68 | rethrow 69 | #.## 70 | yyyy-MM-dd 71 | HH:mm:ss 72 | yyyy-MM-dd HH:mm:ss 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /picture-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | cl 7 | picture 8 | 1.0.0-SNAPSHOT 9 | 10 | picture-server 11 | picture-server 12 | war 13 | 14 | 15 | UTF-8 16 | 4.0.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | cl 23 | privilege-api 24 | 1.0.0-SNAPSHOT 25 | 26 | 27 | 28 | org.jasig.cas.client 29 | cas-client-core 30 | 3.2.1-SNAPSHOT 31 | 32 | 33 | 34 | log4j 35 | log4j 36 | 1.2.16 37 | 38 | 39 | org.slf4j 40 | slf4j-api 41 | 1.6.1 42 | 43 | 44 | org.slf4j 45 | slf4j-log4j12 46 | 1.6.1 47 | 48 | 49 | 50 | org.springframework 51 | spring-core 52 | ${spring.version} 53 | 54 | 55 | org.springframework 56 | spring-beans 57 | ${spring.version} 58 | 59 | 60 | org.springframework 61 | spring-context 62 | ${spring.version} 63 | 64 | 65 | org.springframework 66 | spring-context-support 67 | ${spring.version} 68 | 69 | 70 | org.springframework 71 | spring-web 72 | ${spring.version} 73 | 74 | 75 | org.springframework 76 | spring-webmvc 77 | ${spring.version} 78 | 79 | 80 | org.springframework 81 | spring-aspects 82 | ${spring.version} 83 | 84 | 85 | org.springframework 86 | spring-jdbc 87 | ${spring.version} 88 | 89 | 90 | org.springframework.data 91 | spring-data-redis 92 | 1.3.1.RELEASE 93 | 94 | 95 | 96 | com.alibaba 97 | dubbo 98 | 2.5.3 99 | 100 | 101 | org.springframework 102 | spring 103 | 104 | 105 | netty 106 | org.jboss.netty 107 | 108 | 109 | 110 | 111 | com.github.sgroschupf 112 | zkclient 113 | 0.1 114 | 115 | 116 | 117 | com.caucho 118 | hessian 119 | 4.0.7 120 | 121 | 122 | 123 | org.freemarker 124 | freemarker 125 | 2.3.16 126 | 127 | 128 | 129 | javax.servlet 130 | servlet-api 131 | 2.5 132 | provided 133 | 134 | 135 | jstl 136 | jstl 137 | 1.1.2 138 | 139 | 140 | 141 | commons-beanutils 142 | commons-beanutils 143 | 1.8.3 144 | 145 | 146 | commons-lang 147 | commons-lang 148 | 2.5 149 | 150 | 151 | commons-net 152 | commons-net 153 | 2.2 154 | 155 | 156 | commons-io 157 | commons-io 158 | 2.0 159 | 160 | 161 | commons-fileupload 162 | commons-fileupload 163 | 1.3 164 | 165 | 166 | -------------------------------------------------------------------------------- /picture-server/src/main/webapp/scripts/custom/cl.js: -------------------------------------------------------------------------------- 1 | var Cl = function() { 2 | return { 3 | action: "", 4 | selected: {}, 5 | tableName: "datatable_cl", 6 | modalName: "modal_cl", 7 | formName: "form_cl", 8 | treeName: "tree_cl", 9 | ajaxRequest: function (url,reqParam,callback) { 10 | $.ajax({ 11 | type: 'POST', 12 | url: url, 13 | data: reqParam, 14 | cache: false, 15 | success: callback 16 | }); 17 | }, 18 | refreshDataTable: function(name) { 19 | var oTable = $('#'+name).dataTable(); 20 | oTable.fnDraw(); 21 | }, 22 | updateDataRow: function(tableName,id,idindex,url) { 23 | var data={ 24 | "id":id 25 | }; 26 | Cl.ajaxRequest(url,data,function(result){ 27 | if(!result) return ; 28 | //result = result.replace(/(^\s*)|(\s*$)/g,''); 29 | var oTable = $('#'+tableName).dataTable(); 30 | var nNodes = oTable.fnGetNodes(); 31 | for(var i=0;i' + 61 | '
' + 62 | '
' + 63 | '
' + 64 | ''; 65 | $.fn.modalmanager.defaults.resize = true; 66 | $("
").appendTo($('body')); 67 | }, 68 | showModalWindow: function(modalName,url) { 69 | var $modal = $('#'+modalName); 70 | $('body').modalmanager('loading'); 71 | setTimeout(function(){ 72 | $modal.load(url, '', function(){ 73 | $modal.modal(); 74 | }); 75 | }, 1000); 76 | }, 77 | hideModalWindow: function(modalDiv) { 78 | var $modal = $('#'+modalDiv); 79 | $modal.modal("hide") 80 | }, 81 | initModifyPassword: function(url) 82 | { 83 | var handleValidation = function() { 84 | // for more info visit the official plugin documentation: 85 | // http://docs.jquery.com/Plugins/Validation 86 | var form1 = $('#form_cl_mp'); 87 | var error1 = $('.alert-danger', form1); 88 | var success1 = $('.alert-success', form1); 89 | form1.validate({ 90 | errorElement: 'span', //default input error message container 91 | errorClass: 'help-block', // default input error message class 92 | focusInvalid: false, // do not focus the last invalid input 93 | ignore: "", 94 | rules: { 95 | oldpassword: { 96 | minlength: 2, 97 | required: true 98 | }, 99 | password: { 100 | minlength: 2, 101 | required: true 102 | }, 103 | confirmpassword: { 104 | minlength: 2, 105 | required: true, 106 | equalTo: "#password" 107 | } 108 | }, 109 | invalidHandler: function (event, validator) { //display error alert on form submit 110 | success1.hide(); 111 | error1.show(); 112 | App.scrollTo(error1, -200); 113 | }, 114 | highlight: function (element) { // hightlight error inputs 115 | $(element) 116 | .closest('.form-group').addClass('has-error'); // set error class to the control group 117 | }, 118 | unhighlight: function (element) { // revert the change done by hightlight 119 | $(element) 120 | .closest('.form-group').removeClass('has-error'); // set error class to the control group 121 | }, 122 | success: function (label) { 123 | label 124 | .closest('.form-group').removeClass('has-error'); // set success class to the control group 125 | }, 126 | submitHandler: function (form) { 127 | modify(); 128 | } 129 | }); 130 | } 131 | var handleWysihtml5 = function() { 132 | if (!jQuery().wysihtml5) { 133 | return; 134 | } 135 | if ($('.wysihtml5').size() > 0) { 136 | $('.wysihtml5').wysihtml5({ 137 | "stylesheets": ["http://127.0.0.1/privilege_inc/assets/plugins/bootstrap-wysihtml5/wysiwyg-color.css"] 138 | }); 139 | } 140 | } 141 | var modify = function() { 142 | var data={ 143 | "oldpassword":$("#oldpassword").val(), 144 | "password": $("#password").val() 145 | }; 146 | Cl.ajaxRequest(url,data,function(result){ 147 | if(!result) return ; 148 | result = result.replace(/(^\s*)|(\s*$)/g,''); 149 | if(result == "success"){ 150 | alert("修改成功"); 151 | Cl.hideModalWindow(Cl.modalName); 152 | } else { 153 | alert("旧密码输入错误"); 154 | return ; 155 | } 156 | }); 157 | } 158 | 159 | handleWysihtml5(); 160 | handleValidation(); 161 | } 162 | }; 163 | }(); -------------------------------------------------------------------------------- /picture-server/src/main/java/com/cl/picture/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.cl.picture.controller; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.Calendar; 6 | import java.util.Collections; 7 | import java.util.Date; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.TreeMap; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Controller; 16 | import org.springframework.ui.ModelMap; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.ResponseBody; 19 | 20 | import com.cl.picture.utils.ConfigUtil; 21 | import com.cl.picture.utils.ConstantUtil; 22 | import com.cl.picture.utils.SessionUtil; 23 | import com.cl.picture.utils.StringUtil; 24 | import com.cl.privilege.api.IPrivilegeBaseApiService; 25 | import com.cl.privilege.model.User; 26 | 27 | 28 | 29 | 30 | /** 31 | *主界面及登录验证相关的控制器 32 | */ 33 | 34 | @Controller 35 | @RequestMapping("/controller") 36 | public class IndexController { 37 | 38 | @Autowired 39 | private IPrivilegeBaseApiService privilegeBaseApiService; 40 | @Autowired 41 | private ConfigUtil configUtil; 42 | 43 | @RequestMapping("/main") 44 | public String main(String visitedModule,HttpServletRequest request,ModelMap map) { 45 | 46 | visitedModule = "pi"; 47 | 48 | //初始化用户、菜单 49 | User user = SessionUtil.getSessionUser(request); 50 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,""); 51 | map.put("user", user); 52 | map.put("menus", menus); 53 | 54 | int hours = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); 55 | map.put("hours", hours); 56 | 57 | return "main.ftl"; 58 | } 59 | 60 | @RequestMapping("/logout") 61 | public String logout(HttpServletRequest request) throws Exception 62 | { 63 | SessionUtil.clearSession(request); 64 | //被拦截器拦截处理 65 | return "redirect:" + configUtil.getCasServerUrl()+"/logout?service=" + configUtil.getCasServiceUrl(); 66 | } 67 | 68 | @RequestMapping("/modifypasswordform") 69 | public String modifypasswordform(HttpServletRequest request) throws Exception 70 | { 71 | return "modifypasswordform.ftl"; 72 | } 73 | 74 | @ResponseBody 75 | @RequestMapping("/modifypassword") 76 | public String modifypassword(String oldpassword,String password,HttpServletRequest request) throws Exception 77 | { 78 | if(StringUtil.isStrEmpty(oldpassword) || StringUtil.isStrEmpty(password)) return ConstantUtil.Fail; 79 | //初始化用户、菜单 80 | User user = SessionUtil.getSessionUser(request); 81 | if(!user.getPassword().equals(StringUtil.makeMD5(oldpassword))) return ConstantUtil.Fail; 82 | User newUser = new User(); 83 | newUser.setId(user.getId()); 84 | newUser.setPassword(StringUtil.makeMD5(password)); 85 | newUser.setUpdateDate(new Date()); 86 | newUser.setUpdatePerson(user.getUsername()); 87 | privilegeBaseApiService.updateUserById(newUser); 88 | 89 | //更新session 90 | user.setPassword(newUser.getPassword()); 91 | request.getSession().setAttribute(SessionUtil.SessionSystemLoginUserName,user); 92 | 93 | return ConstantUtil.Success; 94 | } 95 | 96 | @RequestMapping("/view") 97 | public String view(String visitedModule,String visitedResource,HttpServletRequest request,ModelMap map) 98 | { 99 | //初始化用户、菜单 100 | User user = SessionUtil.getSessionUser(request); 101 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,visitedResource); 102 | map.put("user", user); 103 | map.put("menus", menus); 104 | 105 | map.put("visitedModule", visitedModule); 106 | map.put("visitedResource", visitedResource); 107 | 108 | return "view.ftl"; 109 | } 110 | 111 | @RequestMapping("/viewresult") 112 | public String viewresult(String visitedModule,String visitedResource,String year,String month,String no,HttpServletRequest request,ModelMap map) 113 | { 114 | //初始化用户、菜单 115 | User user = SessionUtil.getSessionUser(request); 116 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,visitedResource); 117 | map.put("user", user); 118 | map.put("menus", menus); 119 | 120 | Boolean result = true; 121 | String dt = year + month; 122 | String pathdt = configUtil.getPictureLocation() + dt; 123 | String path = pathdt + File.separator + no; 124 | File dir =new File(path); 125 | if(!dir.exists()) 126 | { 127 | result = false; 128 | } 129 | 130 | List lstFileB = new ArrayList(); 131 | Map> mapFile = new TreeMap>(); 132 | 133 | if(result) 134 | { 135 | File[] file = dir.listFiles(); 136 | 137 | for (int i = 0; i < file.length; i++) { 138 | if(file[i].isDirectory()) continue; 139 | String fileName = file[i].getName(); 140 | String[] fileNameArray = fileName.split("_"); 141 | if(fileNameArray.length != 3) continue; 142 | 143 | if(file[i].getName().indexOf("_b") != -1) 144 | { 145 | lstFileB.add(file[i].getName()); 146 | continue; 147 | } 148 | 149 | if(mapFile.containsKey(fileNameArray[1])) 150 | { 151 | mapFile.get(fileNameArray[1]).add(fileName); 152 | } 153 | else 154 | { 155 | List f = new ArrayList(); 156 | f.add(fileName); 157 | mapFile.put(fileNameArray[1], f); 158 | } 159 | } 160 | 161 | Collections.sort(lstFileB); 162 | } 163 | 164 | map.put("visitedModule", visitedModule); 165 | map.put("visitedResource", visitedResource); 166 | map.put("year", year); 167 | map.put("month", month); 168 | map.put("no", no); 169 | 170 | map.put("result", result); 171 | map.put("mapFile", mapFile); 172 | map.put("lstFileB", lstFileB); 173 | 174 | return "view.ftl"; 175 | } 176 | 177 | @RequestMapping("/upload") 178 | public String upload(String visitedModule,String visitedResource,HttpServletRequest request,ModelMap map) 179 | { 180 | //初始化用户、菜单 181 | User user = SessionUtil.getSessionUser(request); 182 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,visitedResource); 183 | map.put("user", user); 184 | map.put("menus", menus); 185 | 186 | map.put("visitedModule", visitedModule); 187 | map.put("visitedResource", visitedResource); 188 | 189 | return "upload.ftl"; 190 | } 191 | } -------------------------------------------------------------------------------- /picture-server/src/main/webapp/WEB-INF/ftl/main.ftl: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 创力 | 图片中心 - 主页 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | <#include "header.ftl" > 48 | 49 |
50 |
51 | 52 | 53 |
54 | 55 | <#include "sidebar.ftl" > 56 | 57 | 58 |
59 |
60 | 61 |
62 |
63 | 64 |

65 | 图片中心 66 |

67 | 81 | 82 |
83 |
84 | 85 | 86 |
87 |
88 |
89 |
90 |
91 | 图片中心 92 |
93 |
94 |
95 | <#if hours?? && (hours < 12 && hours >= 5 ) > 96 | 上午好! 97 | <#elseif hours?? && (hours >= 12 && hours < 18 )> 98 | 下午好! 99 | <#else> 100 | 晚上好! 101 | 102 | ${user.fullname?default("")} 103 |
104 |
105 |
106 |
107 | 108 |
109 |
110 | 111 |
112 | 113 | 114 | <#include "footer.ftl" > 115 | 116 | 117 | 118 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /picture-server/src/main/java/com/cl/picture/utils/ImageUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.picture.utils; 2 | 3 | import java.awt.Image; 4 | import java.awt.image.BufferedImage; 5 | import java.awt.image.RenderedImage; 6 | import java.io.ByteArrayInputStream; 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.util.Iterator; 13 | import javax.imageio.ImageIO; 14 | import javax.imageio.ImageReader; 15 | import javax.imageio.stream.MemoryCacheImageInputStream; 16 | 17 | /** 18 | * 作者:付学亮 19 | * 版权:北京数字天域 20 | * 创建日期: 2011-10-10 21 | * 此类用途:图片工具类 22 | */ 23 | public final class ImageUtil { 24 | 25 | public static String zoom(String picFrom, String picTo, int size, String formart) { 26 | formart=JPG; 27 | try { 28 | byte[] k1= readFromFile(picFrom); 29 | RenderedImage rendImage =getScaleImage(k1,formart.toUpperCase(), size); 30 | //以下是将图形保存为标准图片格式 31 | ImageIO.write(rendImage,formart.toUpperCase(),new File(picTo)); 32 | } catch (IOException e) { 33 | 34 | } 35 | return picTo; 36 | } 37 | public static void main(String[] args) { 38 | zoom("D:\\93791309846435096972.gif", "D:\\2.bmp", 200, "jpg"); 39 | } 40 | public static final String PNG="png"; 41 | public static final String JPG="jpg"; 42 | public static final String BMP="bmp"; 43 | public static final String GIF="gif"; 44 | public static byte[] readFromFile(String path) throws IOException { 45 | InputStream is = new FileInputStream(new File(path)); 46 | byte[] buf = new byte[is.available()]; 47 | is.read(buf); 48 | is.close(); 49 | return buf; 50 | } 51 | 52 | /** 53 | * 构建一个image对象 54 | * 55 | * @param img 56 | * @return 57 | * @throws IOException 58 | */ 59 | public static ImageInfo getImageInfo(byte[] img) throws IOException { 60 | ByteArrayInputStream bais = new ByteArrayInputStream(img); 61 | MemoryCacheImageInputStream is=new MemoryCacheImageInputStream(bais); 62 | Iterator it=ImageIO.getImageReaders(is); 63 | ImageReader r=null; 64 | while(it.hasNext()){ 65 | r=it.next(); 66 | break; 67 | } 68 | if(r==null){ 69 | return null; 70 | } 71 | ImageInfo i=new ImageInfo(); 72 | i.setType(r.getFormatName().toLowerCase()); 73 | int index=r.getMinIndex(); 74 | /** 75 | * 对于ImageReader的线程安全是不确定的 76 | */ 77 | synchronized (r) { 78 | r.setInput(is); 79 | i.setHeight(r.getHeight(index)); 80 | i.setWidth(r.getWidth(index)); 81 | } 82 | return i; 83 | } 84 | public static BufferedImage getImage(byte[] img) throws IOException { 85 | ByteArrayInputStream bais = new ByteArrayInputStream(img); 86 | BufferedImage src = ImageIO.read(bais); 87 | return src; 88 | } 89 | /** 90 | * 等比例缩放 91 | * @param img 92 | * @param width 93 | * @return 94 | * @throws IOException 95 | */ 96 | public static BufferedImage getScaleImage(byte[] img,String type,int width) throws IOException { 97 | ByteArrayInputStream bais = new ByteArrayInputStream(img); 98 | BufferedImage src = ImageIO.read(bais); 99 | int w=src.getWidth(); 100 | int h=src.getHeight(); 101 | int height=(int) (((float)width/w)*h); 102 | Image im=src.getScaledInstance(width, height,Image.SCALE_SMOOTH); 103 | BufferedImage bi=new BufferedImage(width, height, src.getType()); 104 | bi.getGraphics().drawImage(im, 0, 0,null); 105 | return bi; 106 | } 107 | public static byte[] getScaleImageBytes(byte[] img,String type,int width) throws IOException { 108 | BufferedImage bi=getScaleImage(img, type, width); 109 | ByteArrayOutputStream out=new ByteArrayOutputStream(); 110 | ImageIO.write(bi, type, out); 111 | return out.toByteArray(); 112 | } 113 | /** 114 | * 获取文件类型,没找到返回null,这方法太高效了,可能不准确, 115 | * 这个是我看的网上的,有bug不准确 116 | * @param byte1 117 | * @return 118 | */ 119 | public static String fastParseFileType(byte[] byte1) { 120 | if ((byte1[0] == 71) && (byte1[1] == 73) && (byte1[2] == 70) 121 | && (byte1[3] == 56) && ((byte1[4] == 55) || (byte1[4] == 57)) 122 | && (byte1[5] == 97)) { 123 | return GIF; 124 | } 125 | if ((byte1[6] == 74) && (byte1[7] == 70) && (byte1[8] == 73) 126 | && (byte1[9] == 70)) { 127 | return JPG; 128 | } 129 | if ((byte1[0] == 66) && (byte1[1] == 77)) { 130 | return BMP; 131 | } 132 | if ((byte1[1] == 80) && (byte1[2] == 78) && (byte1[3] == 71)) { 133 | return PNG; 134 | } 135 | return null; 136 | } 137 | public static class ImageInfo{ 138 | private String type; 139 | private int width; 140 | private int height; 141 | public String getType() { 142 | return type; 143 | } 144 | public void setType(String type) { 145 | this.type = type; 146 | } 147 | public int getWidth() { 148 | return width; 149 | } 150 | public void setWidth(int width) { 151 | this.width = width; 152 | } 153 | public int getHeight() { 154 | return height; 155 | } 156 | public void setHeight(int height) { 157 | this.height = height; 158 | } 159 | } 160 | 161 | /** 162 | * 生成缩略图,对于第一张图,生成c颜色图(40*40) 163 | * 对于每张图,生成4种尺寸的图t(60*60),s(160*160),m(240*240),l(480*480),加上原图o(1000*1000),加上b(750*750) 164 | * @param path 165 | * @param ext 166 | */ 167 | public static void CreateZoomPicture(String path,String ext) 168 | { 169 | if(path.indexOf("_o.")==-1) 170 | { 171 | return; 172 | } 173 | //l图 174 | ImageUtil.zoom(path,path.replace("_o", "_l"), 480, ext); 175 | //m图 176 | ImageUtil.zoom(path,path.replace("_o", "_m"), 240, ext); 177 | //s图 178 | ImageUtil.zoom(path,path.replace("_o", "_s"), 160, ext); 179 | //t图 180 | ImageUtil.zoom(path,path.replace("_o", "_t"), 60, ext); 181 | //b图 182 | ImageUtil.zoom(path,path.replace("_o", "_b"), 750, ext); 183 | //对于第一张图,切c图 184 | if(path.indexOf("_01_") !=-1) 185 | { 186 | ImageUtil.zoom(path,path.replace("_o", "_c"), 40, ext); 187 | } 188 | } 189 | } -------------------------------------------------------------------------------- /picture-server/src/main/webapp/scripts/plugin/ajaxfileupload.js: -------------------------------------------------------------------------------- 1 | 2 | jQuery.extend({ 3 | 4 | 5 | createUploadIframe: function(id, uri) 6 | { 7 | //create frame 8 | var frameId = 'jUploadFrame' + id; 9 | var iframeHtml = '