Verify file size only, do not validate pixels
<script>
function Check () {
var size= upload file control. Postedfile.contentlength; Get the size of the uploaded file
if (size>120) {
Alert ("Picture is greater than 120kb");
return false;
}
}
</script>
Verify pixel size
<input name= "txtimg" type= "file" id= "Txtimg"/>
<input name= "btnuploadimg" type= "button" id= "btnuploadimg" value= "Upload"/>
<span class= "Redcolor" > (Best Picture size: Width not exceeding 600 pixels, height not exceeding 600 pixels) </span>
<script language= "JavaScript" >
var allowimgfilesize=512; Allow upload of picture file size 0 for unrestricted units: KB
var allowimgwidth=600; The width of the allowed image to be uploaded is 0 unrestricted: px (pixels)
var allowimgheight=600; The height of the image allowed to upload is 0 unrestricted: px (pixels)
function checkimg () {
var Txtimg=document.getelementbyid ("Txtimg");
if (txtimg.value== "") {
Alert ("Click the browse button, select the JPG or GIF file you want to upload!");
Txtimg.focus ();
return false;
}
&NBSP;
var txtimg_url=txtimg.value.tolowercase ();
var txtimg_ext=txtimg_url.substring (txtimg_url.length-3,txtimg_url.length);
if (txtimg_ext!= "JPG" && txtimg_ext!= "gif") {
alert ("Please select files in jpg or GIF format!");
txtimg.select ()
document.execcommand ("Delete");
Txtimg.focus ();
return false;
}
var errmsgerrmsg = "";//error message
var img=new Image ();
Img.src=txtimg.value;
&NBSP;
if (Img.width > Allowimgwidth) {
Errmsgerrmsg= "\ n \ nthe picture width exceeds the limit please upload the width less than" +allowimgwidth+ "px file, the current picture width is" +img.width+ "px"; &NBSP;
alert (errmsgerrmsg); return false;
if (Img.height > Allowimgwidth) {
Errmsgerrmsg= "\ n \ nthe picture height exceeds the limit please upload the file height less than" +allowimgheight+ "px, the current picture height is" +img.height+ "px";&NBSP;
alert (errmsgerrmsg); return false;
&NBSP;
var size = Formatnum (img.filesize/1024,2);
if (Size > Allowimgfilesize) {
errmsgerrmsg = "\ n \ nthe picture file size exceeds the limit please upload less than" +allowimgfilesize+ " KB of files, the current file size is "+size+" KB "; &NBSP;
alert (errmsgerrmsg); return false;
}
Alert (' ok! ');
return true;
}
</script>
JS Picture Verification Size