HTML
Java Script
Get file extension
var fname=document.getElementById('File_name').files[0].name;
var ext=fname.split('.').pop();
Jquery
check empty file
Check 1 MB File
function getFileSize(id)
{
try {
if ((document.getElementById(id).files[0].size / 1024)
> 1000) {
alert("Sorry Maximum 1 MB file size is allowed"); return false;
}
else
return true;
}
catch (exception)
{
alert('Please select a image file');
return false;
}
}
Show file in img tag selected by input type file control by button click event
HTML
<input type="file" id="MainFile" style="display:inline" accept="image/jpeg,
image/png, image/jpg"/>
<input type="button" value="Upload " class="btn btn-success" onclick="UploadMainImage()" /><br /><br />
<img src="~/AppImage/page/blank-image.jpg" id="imgMain" style="width:200px"/>
Javascript
function UploadMainImage() {
var reader = new
FileReader();
reader.onload = function (e) {
$('#imgMain')
.attr('src', e.target.result);
};
reader.readAsDataURL($("#MainFile")[0].files[0]);
}
No comments:
Post a Comment