diff --git a/templates/orange/html/author/book_add.html b/templates/orange/html/author/book_add.html index 3985f37..a622e04 100644 --- a/templates/orange/html/author/book_add.html +++ b/templates/orange/html/author/book_add.html @@ -142,29 +142,32 @@ + + + diff --git a/templates/orange/html/user/setup.html b/templates/orange/html/user/setup.html index 38c5af1..0a94c66 100644 --- a/templates/orange/html/user/setup.html +++ b/templates/orange/html/user/setup.html @@ -96,45 +96,48 @@ var file = $("#file0").val(); //文件名称 if (file != "") { - $.ajaxFileUpload({ - url : "/file/upload", //用于文件上传的服务器端请求地址 - secureuri : false, //是否需要安全协议,一般设置为false - fileElementId : "file0", //文件上传域的ID - dataType : "json", //返回值类型 一般设置为json - type : "post", - success : function(data) { //服务器成功响应处理函数 - if (data.code == 200) { + if(checkPicUpload($("#file0")[0])) { - $.ajax({ - type: "POST", - url: "/user/updateUserInfo", - data: {'userPhoto':data.data}, - dataType: "json", - success: function (data) { - if (data.code == 200) { - window.location.href = '/user/setup.html'; + $.ajaxFileUpload({ + url: "/file/picUpload", //用于文件上传的服务器端请求地址 + secureuri: false, //是否需要安全协议,一般设置为false + fileElementId: "file0", //文件上传域的ID + dataType: "json", //返回值类型 一般设置为json + type: "post", + success: function (data) { //服务器成功响应处理函数 + if (data.code == 200) { - } else if (data.code == 1001) { - //未登录 - location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href); + $.ajax({ + type: "POST", + url: "/user/updateUserInfo", + data: {'userPhoto': data.data}, + dataType: "json", + success: function (data) { + if (data.code == 200) { + window.location.href = '/user/setup.html'; - } else { - layer.alert(data.msg); + } else if (data.code == 1001) { + //未登录 + location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href); + + } else { + layer.alert(data.msg); + } + + }, + error: function () { + layer.alert('网络异常'); } + }) - }, - error: function () { - layer.alert('网络异常'); - } - }) + } else { + layer.alert(data.msg); + } - }else { - layer.alert('图片上传失败'); } - } - - }); + }); + } } else { alert("请选择上传文件!"); } diff --git a/templates/orange/static/javascript/common.js b/templates/orange/static/javascript/common.js index e844637..e3fa1c8 100644 --- a/templates/orange/static/javascript/common.js +++ b/templates/orange/static/javascript/common.js @@ -124,4 +124,36 @@ String.prototype.isNickName = function () { function logout() { $.cookie('Authorization', null,{ path: '/' }); location.reload(); -} \ No newline at end of file +} + + +function isImg(str) { + return !str.search("[.]+(jpg|jpeg|swf|gif|png|JPG|JPEG|SWF|GIF|PNG)$"); +} + + +//校验图片上传 +function checkPicUpload(file){ + + if(!isImg(file.value.substr(file.value.lastIndexOf(".")))){ + layer.alert('只能上传图片格式的文件!'); + return false; + } + var fileSize = 0; + var isIE = /msie/i.test(navigator.userAgent) && !window.opera; + if (isIE && !file.files) { + var filePath = file.value; + var fileSystem = new ActiveXObject("Scripting.FileSystemfileect"); + var file = fileSystem.GetFile (filePath); + fileSize = file.Size; + }else { + fileSize = file.files[0].size; + } + fileSize=Math.round(fileSize/1024*100)/100; //单位为KB + if(fileSize>=1024){ + layer.alert('上传的图片大小不能超过1M!'); + return false; + } + return true; +} +