-3
這是MySQL表db table containg blob image如何使用PHP從MYSQL插入和檢索圖像blob?
我想要做的是插入圖像,並存儲在「理由」作爲一個blob,然後檢索,並在另一頁表中的顯示。
這是我用來顯示其代碼:
<?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 } ?>
此代碼的工作完美,如果我從phpMyAdmin的手動插入的圖像。 但是當我插入圖像到數據庫與PHP圖像不顯示。
<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));
}}
?>
這是輸出: 第一行中我插入從phpMyAdmin的手動 圖像的第二行中我與代碼 html table displaying the 2 images
[正常圖像存儲或mySQL blob?]可能重複(https://stackoverflow.com/questions/2218537/normal-image-storing-or-mysql-blob) – Rushikumar