我试图从base64编码的表格行中拉出图片。我需要将它们解码并显示在网页上。我真的想把它们放到幻灯片中,但这是另一个话题!从sql中查询base64图像并对其进行解码
这是迄今为止
require("config.inc.php");
//initial query
// table name is pictures and table row is picture
$query = "Select * FROM pictures";
//execute query
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
}
// Finally, we can retrieve all of the found rows into an array using fetchAll
$rows = $stmt->fetchAll();
if ($rows) {
$response["success"] = 1;
$response["message"] = "Photos Available!";
$response["posts"] = array();
// only 3 rows in table - post_id, username, picture
foreach ($rows as $row) {
$post = array();
$post["post_id"] = $row["post_id"];
$post["username"] = $row["username"];
$post["picture"] = $row["picture"];
//update our repsonse JSON data
array_push($response["posts"], $post);
}
// echoing JSON response
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "No Photos Available!";
die(json_encode($response));
}
?>
问题是解码的查询。下面是它显示到目前为止
这只是一个画面(后)的表可能有它的50张图片,并且每个都需要进行显示(因此,对于幻灯片的愿望)。这是我的头,我会很感激任何帮助。
2013-07-30
JeffK
+0
这可能会帮助你通过'http:/stackoverflow.com/questions/2820249/base64-encoding-and-decoding-in-client-side-javascript' –