Examples are as follows:
Determines the photo size
function getphotosize (obj) {
photoext=obj.value.substr (obj.value.lastIndexOf (".")). toLowerCase ()//Get file suffix name
if (photoext!= '. jpg ') {
alert ("Please upload a photo with suffix name jpg!");
return false;
}
var fileSize = 0;
var Isie =/msie/i.test (navigator.useragent) &&!window.opera;
if (Isie &&!obj.files) {
var filePath = obj.value;
var filesystem = new ActiveXObject ("Scripting.FileSystemObject");
var file = Filesystem.getfile (FilePath);
fileSize = file. Size;
} else {
fileSize = obj.files[0].size;
}
Filesize=math.round (filesize/1024*100)/100; The Unit is KB
if (filesize>=10) {
alert ("Photo maximum size is 10KB, please upload it again!");
return false;
}
}
JSP page:
<input type= "File" id= "Imgfile name=" upload "style=" width:150px; "onchange=" getphotosize (this)/>
The above is small series for everyone to bring the JS judge file format and size of a simple example (must see) all the content, I hope that we support cloud Habitat Community ~