jsp :限制用户输入路径
<td height="58" class="b" valign="bottom">
<div align="left"><input type="file" name="address" unselectable="on" style="WIDTH:400px"/></div>
</td>
js 验证图片格式:
/**---------判断是否是图片,符合格式:jpg gif bmp,png,jpeg*/
function isPicture(fileName){
if(fileName!=null && fileName !=""){
//lastIndexOf如果没有搜索到则返回为-1
if (fileName.lastIndexOf(".")!=-1) {
var fileType = (fileName.substring(fileName.lastIndexOf(".")+1,fileName.length)).toLowerCase();
var suppotFile = new Array();
suppotFile[0] = "jpg";
suppotFile[1] = "gif";
suppotFile[2] = "bmp";
suppotFile[3] = "png";
suppotFile[4] = "jpeg";
for (var i =0;i<suppotFile.length;i++) {
if (suppotFile[i]==fileType) {
return true;
} else{
continue;
}
}
//alert("文件类型不合法,只能是jpg、gif、bmp、png、jpeg类型!");
return false;
} else{
//alert("文件类型不合法,只能是 jpg、gif、bmp、png、jpeg 类型!");
return false;
}
}
}
jsp页面调用:
if(document.forms[0].upgradefile.value !=""){
if(!isUpdatePack(document.forms[0].upgradefile.value)){
alert("文件类型不合法,只能是jpg、gif、bmp、png、jpeg类型!");
return false;
}
}