Preview An Image Before It Is Uploaded | Code Factory


Donate : Link

Medium Blog : Link

Applications : 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>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s