0

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.

Community
  • 1
  • 1
ItayAmza
  • 819
  • 9
  • 21

2 Answers2

1

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...

ItayAmza
  • 819
  • 9
  • 21
0

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"] = "test@mm.com";
$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'];
kapil
  • 162
  • 5
  • but im pushing an array array_push($response["adds"], $add) , and all other values are strings... – ItayAmza Apr 16 '13 at 12:09
  • nop! still null. but I did manage to pass the data when I converted the rows on my table from medium text to medium blob, apparently the conversion converted the data into text. how can I, inside the php, convert image into string before inserting it into blob? – ItayAmza Apr 16 '13 at 17:21