【发布时间】: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"]);再次感谢你:)