我試圖從base64編碼的表格行中拉出圖片。我需要將它們解碼並顯示在網頁上。我真的想把它們放到幻燈片中,但這是另一個話題!從sql中查詢base64圖像並對其進行解碼
這是迄今爲止
<?php
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));
}
?>
問題是解碼的查詢。下面是它顯示到目前爲止
http://www.photosfromfriends.com/webservice/gallery.php
這只是一個畫面(後)的表可能有它的50張圖片,並且每個都需要進行顯示(因此,對於幻燈片的願望)。這是我的頭,我會很感激任何幫助。
這可能會幫助你通過'http:/stackoverflow.com/questions/2820249/base64-encoding-and-decoding-in-client-side-javascript' – RiggsFolly