<!DOCTYPE html>
<html>
<head>
	<title>Gambar Preview</title>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
	<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<div class="container-fluid mt-3">
	<div class="row">
		<div class="col-md-3">
			<div class="card text-center shadow-lg  mb-5 bg-white rounded">
				<div class="card-header bg-info text-light">
				    Upload Gambar <br/>
				</div>
				<div class="card-body">
					<form runat="server">
					  <input type='file' id="file" />
					  <img class="img-fluid" id="gambar" src="#" alt="Pilih Gambar" OnError=" $(this).hide();"/>
					</form>
				</div>				
			</div>
		</div>
	</div>
	
</div>
<script type="text/javascript">
function readURL(input) {
  if (input.files && input.files[0]) {
    var reader = new FileReader();
    
    reader.onload = function(e) {
      $('#gambar').attr('src', e.target.result);
    }
    
    reader.readAsDataURL(input.files[0]); // convert to base64 string
  }
}

$("#file").change(function() {
	$('#gambar').show();
   readURL(this);
});
</script>
</body>
</html>