我有供用户绘制的画布。我通过json将canvas的数据传递到php文件,在其中保存数据并使用传递的数据创建文档。如何从json获取绘制的签名并将其保存到文件夹? 这是画布的输入字段:
<div class="form-group text-center" style="width: 202px; margin: 20px auto;">
<label>Sign here: *</label>
<input type="text" class="form-control"
style="visibility: hidden;" id="eSignature"
name="eSignature" data-validation="length"
data-validation-length="min1"
data-validation-error-msg="Please sign in the box.">
<canvas id="signature-pad" class="signature-pad" width="200"
height="100" style="touch-action: none;"></canvas>
<button class="btn btn-danger clear-sign">Clear</button>
</div>
这是ajax:
var signaturePad = new SignaturePad(document.getElementById('signature-pad'), {
backgroundColor: 'rgba(0, 0, 0, 0)',
penColor: 'rgb(89, 128, 212)',
onEnd() {
var val = signaturePad.toDataURL('image/png');
$('input#eSignature').val(val).change();
}
});
$('.clear-sign').on('click', function () {
signaturePad.clear();
$('input#eSignature').val('').change();
});
// This will give you the data from the canvas as base64 encoded Image
signaturePad.toDataURL('image/png');
在发布请求中是这样的:
step-1: {
"firstName":"ddddd",
"lastName":"sssssss",
"dateOfApp":"07-01-2019",
"eSignature":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAMfUlEQVR4Xu1d3Ytd1RX//fYdNWYmJtJqv3VKpfVjEsfSUqGFGYViEVqHWsxEUlRaKJRCxoc GJO/AN0fCj41E5fmpm24PigFOrDhBZaxZY7Tmw1iI0Qo6IkE00yic7dq6xz7pk5dz7vPffr3HPWJZCZuftr/db6sddee 29CfsYAobApgjQsDEEDIHNETCCmHUYAlsgYAQx8zAEjCBmA4ZAOgRsBkmHm9UqCAJGkIIo2sRMh4ARJB1uVqsgCBhBCqJoEzMdAkaQdLhZrYIgYAQpiKJNzHQIGEHS4Wa1CoKAEaQgijYx0yFgBEmHm9UqCAJGkIIo2sRMh4ARJB1uVqsgCBhBCqJoEzMdAkaQdLhZrYIgYAQpiKJNzHQIGEHS4Wa1CoKAEaQgijYx0yFgBEmHm9UqCAJGkIIo2sRMh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tepI09x8jSO5VXJ A4S2XqIzqrj/gwwv9RDC8/mxNIl4WnRh9NTwqQCnnMfPZCFKf/RS6VPXuAd3EHIzCzNS0mXBvZu1HgMsA/qHP2pFurtdnGiNIoU0/vfBrM50T65ma wmik6Wipz7n1D3znv/605Ghv6fvubM1jSCdxTvXvendaFdi W5Nl9mMMNWggO7 vwLgvN4fAPHHspp3ZgTJtcl2V7j9wfGfE/he9Ynt8Jhz8q6C OfoMSTMwcsz00/snenuqGt7N4JkSRs5HosGAQSVSQB3x4mYSYKsXvShqTJ4D3DLgHyoRwFmDu99ulvQGEG6hXxB 43XLh6VHxCyA3A3A/jOJveqhesZDzdXgn 0G3syRpCCGmqWxA4fZ4VMObAmMrbGBYNAztDjl510w4wgWbKUgo8l3rj0Ig8S3E1Cjy HnwRZPpgOhq7vFFRGkE4hbf00jMD wwvPOlJvmFkJHYvgw kjQ9c13FjKCkaQlMBZtfYjUE3pn2B0cOxGgZz1kIN/DPa90P7eox6MIJ1C2vppCgF1v7qRdWwEaUptVjnvCPwfuHrDoUt8zIAAAAAASUVORK5CYII=",
"acceptTerms":"Yes",
"acceptAuth":"Yes"
}
我如何通过php“ eSignature”捕获并将其像图像一样保存在文件夹中?
答案 0 :(得分:1)
在您的php文件中尝试此代码
$data = $jsonDecode["eSignature"];
$data = str_replace('data:image/png;base64,', '', $data);
$data = base64_decode($data);
file_put_contents($newFilePath. "signature.png", $data);