1index.php
2 // image insert
3 $('#insert_form').submit(function(event){
4 event.preventDefault();
5 var image_name = $('#image').val();
6 if(image_name == '')
7 {
8 // alert("Please Select Image");
9 return false;
10 }
11 else
12 {
13 var extension = $('#image').val().split('.').pop().toLowerCase();
14 if(jQuery.inArray(extension, ['gif','png','jpg','jpeg']) == -1)
15 {
16 alert("invalid image file")
17 $('#image').val('');
18 return false;
19 }
20 else
21 {
22 $.ajax({
23 url:"insertimage.php",
24 method:"POST",
25 data:new FormData(this),
26 contentType:false,
27 processData:false,
28 success:function(data)
29 {
30 alert(data);
31 fetch_data();
32 $('#insert_form')[0].reset();
33 $('#imageModal').modal('hide');
34 }
35 });
36 }
37 }
38 });
39
40
41
42
43insertimage.php
44
45if(isset($_POST["action"]))
46 {
47
48 if($_POST["action"] == "insert") // for insert image
49 {
50 $file = addslashes(file_get_contents($_FILES["image"]["tmp_name"]));
51 $query = INSERT INTO table_name (column1) VALUES ('$image');
52 if(!mysqli_query($connection, $query))
53 {
54 die(mysqli_error($connection));
55
56 };
57 }
58 }
59