I am using asp.net and I have a html upload Control from where I have called the ValidatePhotographToUpload
onChange event. I am not been able to validate.
My html code is as follows
<input id="fupEventImage" type="file" size="45" name="LogoUploadedToUpload"
class="imguploader" onchange="return validatePhotographToUpload();" />
My javascript code is as follows:
function ajaxFileUpload() {
$("#FileLoading")
.ajaxStart(function () {
$(this).show();
})
.ajaxComplete(function () {
$(this).hide();
});
$.ajaxFileUpload
(
{
url: '<%=ResolveClientUrl("~/Handlers/AjaxFileUploader.ashx?PG=AddNewList&TY=L")%>',
secureuri: false,
fileElementId: 'fupEventImage',
dataType: 'json',
data: { name: 'logan', id: 'id' },
success: function (data, status) {
if (typeof (data.error) != 'undefined') {
if (data.error != '') {
alert(data.error);
} else {
$('[id$=cropImageTarget]').attr('src', '<%= ResolveClientUrl("~/Handlers/DisplayUploadedImage.ashx?T=")%>' + new Date().getTime());
ShowThumbImage();
$("[id$=BodyContentPlaceHolder_ContentPlaceHolder1_btnClearImage2]").show();
$("#disablelayer").show();
}
}
},
error: function (data, status, e) {
alert(e);
}
}
)
return false;
}
function validatePhotographToUpload() {
var uploadcontrol = $('[id$=fupEventImage]').val();
var ext = uploadcontrol.substring(uploadcontrol.lastIndexOf('.') + 1);
if (ext == 'jpg' || ext == 'jpeg' || ext == 'png' || ext == 'JPG' || ext == 'JPEG' || ext == 'PNG') {
alert(uploadcontrol.length);
alert((uploadcontrol.length / 1024) + 'KB');
if (uploadcontrol.length <= 1048576) {
ajaxFileUpload();
$('[id$=LogoPhotoChangeHiddenField]').val('1');
}
else {
jAlert("Warning!", "File Size is Very Large", "Maximum Allowed Size is 1MB.", "Red", false);
$('[id$=fupEventImage]').val("");
}
}
else {
jAlert("Warning!", "Invalid Image Format", "Supported Format(jpg,jpeg,png)", "Red", false);
$('[id$=fupEventImage]').val("");
}
}
when I upload photo of size 1.24mb I get 8 as a result. I take this Reference. but I didn`t get the result.
Any help are surely appretiated.