php - 如何从数据库内部数据表下载 Canvas 图像

标签 php jquery html mysql datatables

我在 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/

相关文章:

html - 将 div float 到包含 div 的底部

php - 运行 100 多个 MySQL 更新查询。优化提示请:)

php - 如何根据性别和计数翻译 PHP 中的字符串?

jquery - 我网站中的侧边栏菜单问题

javascript - 如何防止弹出窗口时出现滚动条?

html - CSS 在一行图像旁边正确对齐

php - Typo3:可能在 1 台 Linux 服务器上安装 2 个?

php 论坛在提交时未检测到新行

javascript - 隐藏图像后显示图像

javascript - 谷歌地图 API : kml on top of polygon