How to upload image preview in jQuery
This is how to preview the image before it is uploaded using jquery. Preview image before the upload is a mostly use feature for the file upload functionality.
The browser without using Ajax to upload the image.
<!DOCTYPE html>
<html>
<head>
<title>How to upload image preview in jQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<h3>How to upload image preview in jQuery</h3>
<form runat="server" enctype="multipart/form-data" id="uploadForm" method="post">
<input type='file' id="imageInput" name="files" />
<img id="imageDis" src="#" alt="your image" />
</form>
<script type="text/javascript">
$('#imageDis').css('display','none');
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#imageDis').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imageInput").change(function() {
$('#imageDis').css('display','block');
readURL(this);
});
</script>
</body>
</html>
Example :