我有一个保存在 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;
}
该图网址为:数据:图像/ PNG; BASE64,iVBORw0KGgoAAAANSUhEUgAAA4QAAAH0CAYAAABl8 + PTAAAgAElEQVR4Xu3dB9glZ103 / u8LJCHhpQkYCUWlWwAFFZDQO0F6lUAkFEEpghQpvuArRboUAaU36YYWpBMhFP1Lk1clIhZAOoIgCUko / + UHS / pks7vPmTkzZ2bOfOa6zrULue
如何使用上述代码下载图像?
冉冉说