Предпросмотр картинки перед загрузкой на сервер

See this code Preview An Image Before It Is Uploaded on x.xhtml.ru.

html

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

javascipt

<script>
function readURL(input) {
 if (input.files && input.files[0]) {
  var reader = new FileReader();
    
  reader.onloadend = function(e) {
   $('#prevImage').attr('src', e.target.result);
  }
    
  reader.readAsDataURL(input.files[0]);
 }
}
$("#imageFile").change(function() {
 readURL(this);
});
</script>