
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="container">  
  <h3 align="center" class="mb-3 mt-3">Dewan Upload &amp; Resize/Compress Gambar dengan Ajax</h3>

  <form method="post" id="upload_image" enctype="multipart/form-data">
    <label>Select File</label>
    <input type="file" name="image_upload" id="image_upload" class="form-control" />
    <input type="submit" name="upload" id="upload" class="btn btn-info mt-5" value="Upload" />
  </form>

  <div id="preview"></div>  
</div>

<form method="post" action="upload.php" id="upload_image" enctype="multipart/form-data">
    
    
<script>
  $(document).ready(function(){
    $('#upload_image').on('submit', function(event){
      event.preventDefault();
      $.ajax({
        url:"upload.php",
        method:"POST",
        data:new FormData(this),
        contentType:false,
        cache:false,
        processData:false,
        success:function(data){
          $('#preview').html(data);
        }
      })
    });
  });
</script>    