Copy Code code as follows:
<form name=myform onsubmit= "return checkfilesize ()" >
<input Type=file name=photo><br/>
<input Type=submit value=submit></form>
<script language= "JavaScript" ><!--
function Checkfilesize ()
{
var s = document. Myform.photo.value;
if (s== "") return false;
var img = new Image ();
IMG.SRC = s;
Alert ("high =" + Img.height + "\ n width =" + img.width);
Alert ("fileSize =" + img.filesize + "byte");
return false;
}
--></script>
The FileSize attribute of JavaScript and IMG itself under IE is applied. In addition, IMG has several other attributes, such as Filecreateddate, Filemodifieddate, FileSize, fileupdateddate, filters, we can use these properties to get part of the picture file information, such as file size , we use the file form with the IMG tag to determine whether the size of the picture file is legal before uploading.
Copy Code code as follows:
<input type= "Text" size= "4" value= "ten" name= "Filesizelimit" id= "Filesizelimit"/> K
<input type= "File" Name= "File1" id= "file1" size= "" Onchange= "Changesrc" (This)/>
<script type= "Text/javascript" >
var ofilechecker = document.getElementById ("Filechecker");
function Changesrc (filepicker)
{
OFILECHECKER.SRC = Filepicker.value;
}
Ofilechecker.onreadystatechange = function ()
{
if (ofilechecker.readystate = = "complete")
{
Checksize ();
}
}
function Checksize ()
{
var limit = document.getElementById ("Filesizelimit"). Value * 1024;
if (Ofilechecker.filesize > Limit)
{
Alert ("Too large");
}
Else
{
Alert ("OK");
}
}
</script>
Copy Code code as follows:
function Checkfilesize ()
{
var filemaxsize = 100;//Limit uploaded file size, unit (k)
var s = document. RegForm.Img_1.value;
if (s== "") {alert ("No image,please select again!"); Document. RegForm.Img_1.focus (); return false;}
var img = new Image ();
IMG.SRC = s;
if (img.filesize>filemaxsize*1024) {alert ("The file size exceeds" +filemaxsize+ "k,please choose a smaller one!"); Document. RegForm.Img_1.focus (); return false;}
--></script>
<form action= "**.asp" method= "POST" onsubmit= "return Checkfilesize ()" enctype= "Multipart/form-data" Name= "RegForm ">
<input name= "Next" type= "Submit" class= "PBTTN" id= "Next" value= "Save" >