Hello I am using a table for the blob images that contains the images and a client column to reference it the question is how can I display an image blob based on the clientid so that I can show it in the webpage using yii 2?
Here is a screenshot of the table.
Because in this particular article I got the impression it is only uploading the image as BLOB. Yii2 Display image stored in BLOB database field
But how do I make it so that I would only returning/displaying the blob from the database?
EDIT 1
I converted the answer into yii code.
Controller
public function DisplayBlob($clientid){
$model = new Slimages();
return $model->DisplayBlob($clientid);
}
Here is the model.php
public static function DisplayBlob($clientid){
return static::find()->where(['clientid' => $clientid])->asArray()->all();
// $db = $db = mysqli_connect("localhost","root","","myenrollment"); //keep your database name
// $sql = "SELECT * FROM slimages WHERE clientid = $clientid"; // pass your clientid here
// $statement = $db->query($sql);
// $result = mysqli_fetch_array($statement);
// return $result;
//echo '<img src="data:image/jpeg;base64,'.base64_encode($result['Picture'] ).'"/>';
}
View file
<td colspan="2"><?php
$result = SiteController::DisplayBlob($_user);
foreach($result as $image){
// echo 'hello';
echo '<img src="data:image/jpeg;base64,'.base64_encode($image['Picture'] ).'" height="100" width="100"/>';
}
?></td>