Preview An Image Before It Is Uploaded | Code Factory

Code Factory
1 min readApr 4, 2020

--

Reference Link : Link

Donate : Link

html

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type='file' id="imageFile" />
<img id="prevImage" src="#" alt="Image" />
</form>

javascript

<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();

reader.onload = function(e) {
$('#prevImage').attr('src', e.target.result);
}

reader.readAsDataURL(input.files[0]);
}
}
$("#imageFile").change(function() {
readURL(this);
});
</script>

--

--