function verificationPicFile(file) { var fileSize = 0; var fileMaxSize = 1024;//1M var filePath = file.value; if(filePath){ fileSize =file.files[0].size; var size = fileSize / 1024; if (size > fileMaxSize) { alert("文件大小不能大於1M!"); file.value = ""; return false; }else if (size <= 0) { alert("文件大小不能爲0M!"); file.value = ""; return false; } }else{ return false; } }
function verificationPicFile(file) { var filePath = file.value; if(filePath){ //讀取圖片數據 var filePic = file.files[0]; var reader = new FileReader(); reader.onload = function (e) { var data = e.target.result; //加載圖片獲取圖片真實寬度和高度 var image = new Image(); image.onload=function(){ var width = image.width; var height = image.height; if (width == 720 | height == 1280){ alert("文件尺寸符合!"); }else { alert("文件尺寸應爲:720*1280!"); file.value = ""; return false; } }; image.src= data; }; reader.readAsDataURL(filePic); }else{ return false; } }