日期:2014-05-17  浏览次数:20670 次

jsp使用MultipartRequest上传图片怎么判断图片的后缀名是否为"jpg","jpeg"正确的格式呢??
jsp使用MultipartRequest上传图片怎么判断图片的后缀名是否为"jpg","jpeg"正确的格式呢??

------解决方案--------------------
js端直接判断即可。

JScript code

//校驗上傳檔案表單  
    function doCkeck(){  
        var strFile = document.getElementById("fileData").value;  
        if(strFile =="" || strFile == null){  
            alert("請選擇上傳檔案!");  
            return false;  
        }else{  
            //檔案擴展名稱  
            var fileExt = document.getElementById("fileData").value.substr(document.getElementById("fileData").value.lastIndexOf(".")).toLowerCase();  
            var allowExt = ".jpg|.gif|.png|.bmp|.pdf|.doc|.docx|.xls|.xlsx|.msg|.xml|.txt|.mail|.ppt|.zip|";              
            if(allowExt != 0 && allowExt.indexOf(fileExt + "|") == -1){  
                alert("請上傳【.jpg|.gif|.png|.bmp|.pdf|.doc|.docx|.xls|.xlsx|.msg|.xml|.txt|.mail|.ppt|.zip】類型的檔案!");  
                return false;  
            }  
              
        }  
        return true;  
    }