javascript - saving a image in database using blob in foreach -
i created dynamic textboxes, other 1 has type of file, problem dont know how save image in database , have copy of inside folder cause im gonna retrieve later on. since in array form dont have idea how it. used blob it, if have better way , lets see. know how make copy of inside folder dont use foreach dont know. heres code:
<script type="text/javascript"> $(document).ready(function () { $("#append").click(function (e) { e.preventdefault(); var textboxes = $(".textbox").length; $(".inc").append("<div class='controls'><input class='textbox form-control' type='file' name='textbox[]'><input class='textbox form-control' type='text' name='box[]' ><input class='textbox form-control' type='text' name='box1[]' ><input class='textbox form-control' type='text' name='box2[]' ><a href='#' class='remove_this btn btn-danger'>remove</a> </div>"); }); $(document).on('click', '.remove_this', function (e) { e.preventdefault(); $(this).parent().remove(); }); }); </script>
html:
<form class="form-horizontal" method= "post"> <div class="control-group"> <div class="inc"> <div class="controls"> <button style="margin-left: 50px" class="btn btn-info" type="submit" id="append" name="append"> add textbox</button> <br> <br> </div> </div> <input type="submit" class="btn btn-info" name="submit" value="submit"/> </div>
php:
<?php $host = "localhost"; $dbname = "lala"; $user = "root"; $pass = ""; $conn = new pdo("mysql:host=$host; dbname=$dbname", $user, $pass); if (isset($_post['submit'])) { $textboxes = $_post['textbox']; $textboxes1 = $_post['box1']; $textboxes2 = $_post['box2']; $boxes = $_post['box']; $textboxes=addslashes(file_get_contents($_files['textboxes']['tmp_name'])); $image_name1=addslashes($_files['textboxes']['name']); $image_size1=getimagesize($_files['textboxes']['tmp_name']); move_uploaded_file($_files['textboxes']['tmp_name'],"images/".$_files['textboxes']['name']); $location1="images/".$_files['textboxes']['name']; foreach ($location1 $key => $textbox ) { $box=$textboxes[$key]; $box1=$textboxes1[$key]; $box2=$textboxes2[$key]; $sql = "insert sasa (sasa,sasa1,sasa2,sasa3) values('$textbox','$box','$box1','$box2')"; echo $sql . "<br>"; $q = $conn->query($sql); }
} ?>
Comments
Post a Comment