我在 MYSQL 数据库中保存了一个 Canvas 图像,可以使用数据表和 PHP 在表中看到该图像,但我无法下载该图像。
这是我的 JS 文件,它将 ajax 请求发送到服务器:
$(document).ready(function(){
var data = $('#dataList').DataTable({
"lengthChange": false,
"processing":true,
"order":[],
"ajax":{
url:"/php/process.php",
type:"POST",
data:{action:'listData'},
dataType:"json"
},
"columnDefs":[
{
"targets":[0, 5, 6],
"orderable":true,
},
],
"pageLength": 10
});
这是process.php
$sqlQuery = "SELECT * FROM table1 AS a LEFT JOIN sketch AS s ON a.id= s.id";
$auftragData = array();
$result = $this->dbc -> prepare($sqlQuery);
$result -> execute();
while ( $tableResult= $result->fetch(PDO::FETCH_ASSOC) ) {
$resultRows = array();
$resultRows[] = $tableResult['id'];
$resultRows[] = ucfirst($tableResult['cust_id']);
$resultRows[] = $tableResult['typ'];
$resultRows[] = $tableResult['status'];
$resultRows[] = $tableResult['sketch'];
if ($tableResult['sketch']) {
$resultRows[] = '<a id="download" download="sketch.png"><button type="button">Download Image</button></a>';
}
$resultRows[] = '<button type="button" name="update" id="'.$tableResult["id"].'" class="btn btn-warning btn-xs update">update</button>';
$resultRows[] = '<button type="button" name="delete" id="'.$tableResult["id"].'" class="btn btn-danger btn-xs delete" >delete</button>';
$finalData[] = $auftragRows;
}
$numRows = $result -> rowCount();
$output = array(
"draw" => $numRows,
"recordsTotal" => $numRows,
"recordsFiltered" => $numRows,
"data" => $finalData
);
echo json_encode($output);
$this->dbc = NULL;
exit;
}
图片网址是: 数据:图像/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4QAAAH0CAYAAABl8+PTAAAgAElEQVR4Xu3dB9glZ103/u8LJCHhpQkYCUWlWwAFFZDQO0F6lUAkFEEpghQpvuArRboUAaU36YYWpBMhFP1Lk1cl IhZAOoIgCUko/+uHs/pks7vPmTkzZ2bOfOa6zrULue
如何使用上述代码下载图像?
最佳答案
发现问题了。 MySQL DB 中的字段正在剪切字符,同时将图像保存在服务器上。这解决了问题。
关于php - 如何从数据库内部数据表下载 Canvas 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57614942/