如何从mysql表中获取img并对其进行编码,然后将其作为JSON发送给android


How to fetch from mysql table an img and encode it and send it as a JSON to android

我想从mysql记录中获取一个imgs。我读过如何将其发送到android,我意识到它必须将其编码到base64,然后在android中解码所以我只想知道如何从表中获取img并对其进行解码?我不想使用url()并发送它!我只想把解码字符串发送到android??

这是我的php代码

**<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$obj = new DB_CONNECT();
 $con=$obj->connect();
     $result =mysqli_query($con,"SELECT * FROM doctors ");
    if (!empty($result)) {
        if (mysqli_num_rows($result) > 0) {
            $result = mysqli_fetch_array($result);
            $product = array();
            $product["d_id"] = $result["d_id"];
            $product["name"] = $result["name"];
            $product["major"] = $result["major"];
            $product["clinic"] = $result["clinic"];
            $product["img"] = $result["img"];
            $response["success"] = 1;
            $response["product"] = array();
            array_push($response["product"], $product);
            echo json_encode($response);
        } else {
            $response["success"] = 0;
            $response["message"] = "No data found";
            echo json_encode($response);
        }
    } else {
        $response["success"] = 0;
        $response["message"] = "No data found";
        echo json_encode($response);
    }
?>**

看起来你只需要更改$product["img"]=$result["img"];到$product["img"]=base64_encode($result["img"]);。