【问题标题】:How to insert canvas image into the database after i converting to base64转换为base64后如何将画布图像插入数据库
【发布时间】:2020-03-02 03:10:27
【问题描述】:

Javascript

document.getElementById("input1").value=canvas.toDataURL('image/png');

codetreatment.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>

但是这个数据库代码不起作用。

将画布图像转换为base64字符串后的下一步是什么?我要保存到数据库中

【问题讨论】:

  • 为什么不能直接保存为base64字符串?
  • 因为base64的尺寸太大了
  • 可能比将其存储在文件系统上并存储文件路径。
  • 您对将画布图像保存到数据库有什么建议?对不起,先生,我是这里的新手,只是一个学生
  • 狄芬爵士怎么办?

标签: javascript php mysql file canvas


【解决方案1】:

数据库

$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);

【讨论】:

猜你喜欢
  • 2018-06-26
  • 2016-04-30
  • 1970-01-01
  • 2018-02-17
  • 1970-01-01
  • 2016-09-04
  • 2015-02-20
  • 2017-09-08
  • 1970-01-01
相关资源
最近更新 更多