首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从数据库中下载画布映像

如何从数据库中下载画布映像
EN

Stack Overflow用户
提问于 2019-08-22 18:09:05
回答 1查看 114关注 0票数 0

我有一个保存在MYSQL数据库中的画布图像,它可以在使用可数据和PHP的表中看到,但我无法下载该映像。

下面是我的JS文件,它将ajax请求发送到服务器:

代码语言:javascript
复制
$(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

代码语言:javascript
复制
$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

如何用上面的代码下载图像?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-23 19:47:59

发现了问题。MySQL DB中的字段正在切割字符,同时将图像保存在服务器上。解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57614942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档