判断上传图片的脚本
<script>
var loadNum=0;
var loadTimes = 3;
var checkShowSize = false;
var alertmsg = "您选中的图片有问题,请换张图片上传";
function PriviewPic()
{
if(document.Form1.TextFieldUpPic.value=="")
{
return true;
}
document.all.view.src = document.Form1.TextFieldUpPic.value;
var width=500;
var maxfilesize = 204800;
var showimg = new Image();
showimg.src = document.Form1.TextFieldUpPic.value;
if(showimg.width > width)
{
var ori_w= showimg.width;
var ori_h = showimg.height;
showimg.width = width;
showimg.height = ori_h * showimg.width / ori_w;
}
document.all.view.style.width = showimg.width;
document.all.view.style.height = showimg.height;
if(showimg.fileSize>0)
{
if(showimg.fileSize > maxfilesize)
{
alertmsg = "您选中的图片大于" + maxfilesize+ ",目前字节数=" + showimg.fileSize;
return false;
}
checkShowSize = true;
}
else if(loadNum<loadTimes)
{
loadNum ++ ;
setTimeout('PriviewPic()',500);
}
else if(loadNum>=loadTimes)
{
loadNum = 0;
alertmsg = "您选中的图片有问题,请换张图片上传";
return false;
}
}
function UpPic()
{
if(document.Form1.TextFieldUpPic.value=="")
{
return true;
}
if(!checkShowSize)
{
setTimeout('PriviewPic()',500);
alert(alertmsg);
return false;
}
var filename = document.Form1.TextFieldUpPic.value.toLowerCase();
var filext = filename.substring(filename.length-3,filename.length);
if(filext!="jpg" && filext!="gif")
{
alert("您上传的图片不是jpg或gif格式");
return false;
}
return true;
}
</script>