Javascript
document.getElementById("input1").value=canvas.toDataURL('image/png');
代码处理.php
$data = $_POST["input1"];
$data = str_replace('data:image/png;base64,', '', $data);
$data = str_replace(' ','+',$data);
$data = base64_decode($data);
php:
<form action="codetreatment.php" method="post">
<input type="text" name="input1" id="input1" >
<button type="submit" name="treatmenthistoryupdatebtn" class="btn btn-primary">Save</button>
</form>
但是这个数据库代码不起作用。
将 Canvas 图像转换为 Base64 字符串后下一步是什么?我想保存到数据库
最佳答案
数据库
$data = $_POST["input1"];
$data = explode(",", $data)[1];
$decoded_image = base64_decode($data);
$temp_name = 'http://your-domain.com/folder/'.md5(time().rand().time()).".png";
file_put_contents($temp_name, $decoded_image);
// Store this $file to table.
$file = basename($temp_name);
关于javascript - 转换为 Base64 后如何将 Canvas 图像插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60482049/