this is mysql table db table containg blob image
what i'm trying to do is insert an image and store in ' justification' as a blob and then retrieve it and display it in a table in another page.
this is my code for displaying it :
<?php
while ($row = $rep->fetch()) { //$row contains the previous table's data
$image = $row['justification']; //justification is the blob image
$encoded_image = base64_encode($image); ?>
<tr>
<td><?php echo $row['ncarte']; ?></td>
<td><?php echo $row['module']; ?></td>
<td><?php echo $row['type']; ?></td>
<td><?php echo $row['dateabs']; ?></td>
<td><?php echo "<a href='data:image/png;base64,{$encoded_image}' download> <img height='30px' src='data:image/png;base64,{$encoded_image}'> </a>";?> </td>
</tr>
<?php } ?>
this code works perfectly if i insert the image manually from phpMyAdmin. but when i insert the image to the database with php the image doesn't show up.
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" >
<label for="module" >Module :</label>
<select name="module">
<?php foreach ($module as $mod) { ?>
<option value="<?php echo $mod; ?>" > <?php echo $mod; ?> </option>
<?php } ?>
</select>
<br>
<label for="type" >type :</label>
<select name="type">
<?php foreach ($type as $ty) { ?>
<option value="<?php echo $ty; ?>" > <?php echo $ty; ?> </option>
<?php } ?>
</select>
<br>
<label for="date" >Date :</label>
<select name="date">
<?php foreach ($date as $dat) { ?>
<option value="<?php echo $dat; ?>" > <?php echo $dat; ?> </option>
<?php } ?>
</select>
<br>
<input type="file" name="image"/>
<br>
<input type="submit" name="submit"/>
</form>
<?php
if(count($_FILES) > 0) {
if(is_uploaded_file($_FILES['image']['tmp_name'])) {
$date_of_abs = $_POST['date'];
$type_of_abs = $_POST['type'];
$module_of_abs = $_POST['module'];
$imgData =addslashes(file_get_contents($_FILES['image']['tmp_name']));
$sql = $bdd->prepare("UPDATE abs SET justification=? WHERE ncarte=? and module=? and type=? and dateabs =?");
$sql->execute(array(,$imgData,$_SESSION['etudiant'],$module_of_abs,$type_of_abs,$date_of_abs));
}}
?>
this is output : in the first row i inserted the image from phpMyAdmin manually in the second row i inserted the same image with code html table displaying the 2 images