1$(document).ready(function(){
2
3 $("#but_upload").click(function(){
4
5 var fd = new FormData();
6 var files = $('#file')[0].files[0];
7 fd.append('file',files);
8
9 $.ajax({
10 url: 'upload.php',
11 type: 'post',
12 data: fd,
13 contentType: false,
14 processData: false,
15 success: function(response){
16 if(response != 0){
17 $("#img").attr("src",response);
18 $(".preview img").show(); // Display image element
19 }else{
20 alert('file not uploaded');
21 }
22 },
23 });
24 });
25});