【问题标题】:How to fetch from mysql table an img and encode it and send it as a JSON to android如何从 mysql 表中获取 img 并对其进行编码并将其作为 JSON 发送到 android
【发布时间】:2015-04-23 21:07:17
【问题描述】:

我想从 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"] = base64encode($result["img"]); 即可。
  • 谢谢你,它工作 100% =D 你错过了下划线 (_) $product["img"] = base64_encode($result["img"]);再次感谢你:)

标签: php android image encode


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2012-08-05
    相关资源
    最近更新 更多