如何在php中将签名图像插入mysql数据库并检索签名图像

如何在php中将签名图像插入mysql数据库并检索签名图像,php,html,mysql,digital-signature,signaturepad,Php,Html,Mysql,Digital Signature,Signaturepad,我正在尝试将签名图像数据插入数据库,但失败。我刚刚发现如何将签名图像传递到pc中的文件夹中,我可以看到每个图像在文件夹中都有不同的“name.png”,我认为“name.png”可以保存在数据库中。我不知道如何使它成功地保存到数据库中 这是我在模式中制作的签名板代码: <div class="row mb-4"> <a href="#" class="btn btn-lg btn-success" data-toggle="modal" data-target="#ba

我正在尝试将签名图像数据插入数据库,但失败。我刚刚发现如何将签名图像传递到pc中的文件夹中,我可以看到每个图像在文件夹中都有不同的“name.png”,我认为“name.png”可以保存在数据库中。我不知道如何使它成功地保存到数据库中

这是我在模式中制作的签名板代码:

  <div class="row mb-4">
  <a href="#" class="btn btn-lg btn-success" data-toggle="modal" data-target="#basicModal">Client 
   Signature</a>
  </div>
  </div>

  <div class="modal fade" id="basicModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" 
   aria-hidden="true">
   <div class="modal-dialog">
   <div class="modal-content">
   <div class="modal-header">
    <h4 class="modal-title" id="myModalLabel">Client Signature</h4>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
    </div>
    <div class="modal-body">
    <div id="signArea" >

    <h2 class="tag-ingo" style="font-size:30px;color:blue">Put signature below,</h2>

    <div class="typed" ></div>
   <p align="center">  
   <canvas class="sign-pad" id="sign-pad" width="300" height="100"></canvas></p>
   </div>

  </div>
  <div class="modal-footer">
  <button input="reset"  class="btn btn-secondary" >Reset</button>
  <button id="btnSaveSign" type="submit" name="submit" class="btn btn-primary">Submit</button>

客户签名
&时代;
在下面签名,

重置 提交
这是我将签名图像保存到文件夹中的代码:

     <script>
        jQuery(document).ready(function() {
            Main.init();
            FormElements.init();
        });

        $(document).ready(function() {
            $('#signArea').signaturePad({drawOnly:true, drawBezierCurves:true, lineTop:90});
        });

        $("#btnSaveSign").click(function(e){
            html2canvas([document.getElementById('sign-pad')], {
                onrendered: function (canvas) {
                    var canvas_img_data = canvas.toDataURL('image/png');
                    var img_data = canvas_img_data.replace(/^data:image\/(png|jpg);base64,/, "");
                    //ajax call to save image inside folder
                    $.ajax({
                        url: 'save_sign.php',
                        data: { img_data:img_data },
                        type: 'post',
                        dataType: 'json',
                        success: function (response) {
                           window.location.reload();
                        }
                    });
                }
            });
        });
      </script> 

jQuery(文档).ready(函数(){
Main.init();
FormElements.init();
});
$(文档).ready(函数(){
$(#signArea').signaturePad({drawOnly:true,drawBezierCurves:true,lineTop:90});
});
$(“#btnSaveSign”)。单击(函数(e){
html2canvas([document.getElementById('sign-pad')]{
onrendered:函数(画布){
var canvas_img_data=canvas.toDataURL('image/png');
var img_data=canvas_img_data.replace(/^data:image\/(png | jpg);base64,/,“”);
//ajax调用将图像保存在文件夹中
$.ajax({
url:“save_sign.php”,
数据:{img_数据:img_数据},
键入:“post”,
数据类型:“json”,
成功:功能(响应){
window.location.reload();
}
});
}
});
});
这是save-sign.php代码:

<?php 

$result = array();
$imagedata = base64_decode($_POST['img_data']);
$filename = md5(date("dmYhisA"));
//Location to where you want to created sign image
$file_name = './doc_signs/'.$filename.'.png';
file_put_contents($file_name,$imagedata);
$result['status'] = 1;
$result['file_name'] = $file_name;
echo json_encode($result);
?>

这是我在文件夹中检索图像的代码:

<img src="<?php echo $image; ?>" class="sign-preview" />
“class=”签名预览“/>

数据库名称为'appointment',图像数据应在'imagename'中。

数据库名称为'appointment'或表名?您是否已连接数据库(如mysqli\u connect)或者您需要skratch的解决方案吗?您是如何为每个图像文件生成唯一的名称的?这也可以用作表中的insert吗?或者至少您可以将其存储在文本文件中,然后使用MySQL加载数据填充并从那里处理插入操作?只是一些想法我正在考虑将图像插入数据库,而不是插入到我的电脑中的e文件夹。@chrisshow我可以在数据库中插入唯一的名称…@tcadidot0Sorry@nuratiqa但我不熟悉php或jquery,也不熟悉如何在mysql数据库中插入图像。但是我在谷歌上快速搜索了“如何使用php在mysql数据库中插入图像”,这里有很多建议。你可能想试试,看看哪一个可以满足您的条件。;)数据库名或表名?是否已连接数据库(如mysqli_connect)或者您需要skratch的解决方案吗?您是如何为每个图像文件生成唯一的名称的?这也可以用作表中的insert吗?或者至少您可以将其存储在文本文件中,然后使用MySQL加载数据填充并从那里处理插入操作?只是一些想法我正在考虑将图像插入数据库,而不是插入到我的电脑中的e文件夹。@chrisshow我可以在数据库中插入唯一的名称…@tcadidot0Sorry@nuratiqa但我不熟悉php或jquery,也不熟悉如何在mysql数据库中插入图像。但是我在谷歌上快速搜索了“如何使用php在mysql数据库中插入图像”,这里有很多建议。你可能想试试,看看哪一个可以满足你的条件