留言板
AUI validation for image size
Hi All,
How can i validate the image which has less than 40KB sizes only..
Thanks&Regards
How can i validate the image which has less than 40KB sizes only..
Thanks&Regards
AlloyUI doesn't have access to image size in bytes, only dimensions like width and height.
Siraj Choudhary,修改在10 年前。
RE: AUI validation for image size
Junior Member 帖子: 31 加入日期: 13-11-13 最近的帖子
use javascript to get the size of a file, call this function onchange..and have one boolean flag as true ( var uploadSize=true ) in my code.. and write aui custom validator..
below is the code for file size validation..
Siraj Choudhary
below is the code for file size validation..
var uploadSize=true;
function setUploadSize(fileInput)
{
var size=0;
for(var num1=0;num1<fileinput.files.length;num1++) { var file="fileInput.files[num1];" if(file.size>5242880)
{
document.getElementById('<portlet:namespace />copyUpload').focus();
uploadSize=false;
}else{
uploadSize=true;
}
size+=file.size;
}
}
<aui:input name="copyUpload" type="file" label="Upload Scanned Property Card" helpmessage="Accept only Pdf Format" style="width:200px" onchange="setUploadSize(this)" id="copyUpload">
<aui:validator name="custom" errormessage="File size should not be more than 5Mb">
function(val,node,junction){
if(uploadSize==true){
return true;
}else{
return false;
}
}
</aui:validator>
</aui:input>
</fileinput.files.length;num1++)>
Siraj Choudhary