Reputation: 959
I post few days ago Pass MySQL medium blob into IOS NSData\UIImage but didn't manage to find a solution yet. my specific problem is that when I retrieve images from database, blob or text, it returns NULL, rows that don't have variables in them just return blank
while ($row = mysql_fetch_array($result)) {
$add = array();
$add["Id"] = $row["Id"];
$add["Mail"] = $row["Mail"];
$add["Category"] = $row["Category"];
$add["Phone"] = $row["Phone"];
$add["Msgs"] = $row["Msgs"];
//image from blob
$add["Picture"] = $row["Picture"];
// push single add into final response array
array_push($response["adds"], $add);
}
is there any other way to address images from blob\text?! I tried https://stackoverflow.com/a/6273415/1333294 but nothing works for me.
Upvotes: 0
Views: 2550
Reputation: 959
Finally!!
$img = $row["Picture"];
$b64img = base64_encode ($img);
$b64img = mysql_real_escape_string($b64img);
$add["Picture"] = $b64img;
simple as that! and xcode get it as base64 string and nut NULL. thanks for suggestions...
Upvotes: 1
Reputation: 162
Add the following code
header("Content-type: image/jpeg");
echo $row['picture'];
// Display image with img html tag
echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['picture'] ) . '" />';
echo 'Hello world.';
please find sample code
$response["adds"] = array();
$add = array();
$add["Id"] = 1;
$add["Mail"] = "[email protected]";
$add["Category"] = "category";
$add["Phone"] = "1234567";
$add["Msgs"] = "ths s txt msg";
//image from blob
$add["Picture"] = "pciture";
// push single add into final response array
array_push($response["adds"], $add);
print_r($response["adds"]);
header("Content-type: image/jpeg");
print $response["adds"][0]['Picture'];
Upvotes: 0