[英]Saving Canvas image into mysql db as blob datatype
In My Project I got a canvas image and already sent to server, test.php, as shown below: 在“我的项目”中,我得到了一个画布图像,并且已经将其发送到服务器test.php,如下所示:
define('UPLOAD_DIR', '../uploads/');
$img = $_POST['canImg'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
if($success)
echo "success";
else
echo "failed";
My Question is, how to save the file in to blob mysql field? 我的问题是,如何将文件保存到Blob mysql字段中?
Establish MySQL connection, create the image table with the field img_data and other fields as needed , then something like this: 建立MySQL连接,根据需要使用img_data字段和其他字段创建映像表,如下所示:
if (!mysqli_query($con,
"insert into images (img_id, img_data) values (".
(int)$img_id.",'".mysqli_real_escape_string($con, $img_data)."')"))
{
// handle error
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.