我有一个保存在MYSQL数据库中的画布图像,它可以在使用可数据和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;
}Img url是: data:image/png;base64 64,iVBORw0KGgoAAAANSUhEUgAAA4QAAAH0CAYAAABl8+PTAAAgAElEQVR4Xu3dB9glZ103/u8LJCHhpQkYCUWlWwAFFZDQO0F6lUAkFEEpghQpvuArRboUAaU36YYWpBMhFP1Lk1clIhZAOoIgCUko/+uHs/pks7vPmTkzZ2bOfOa6zrULue
如何用上面的代码下载图像?
发布于 2019-08-23 19:47:59
发现了问题。MySQL DB中的字段正在切割字符,同时将图像保存在服务器上。解决了这个问题。
https://stackoverflow.com/questions/57614942
复制相似问题