afficher une fichier image a partir de MYSQL database
je suis un etudiant debutant en php et je suis bloque sur un bout de code pour mon projet de fin d'annee. En voici deux fichiers que j'ai creer pour enregistrer des images dans une database et puis les afficher suivant que l'utilisateur demande plus de details sur ce produit:
1) fichier short_items recupere quelque details du produits a partir de la table product et affiche un liens au fichier views_items pour voir plus de details sur le produits a savoir son description et son image, le code de ce fichier:
short_items.php:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <?php
include("config.php");
mysql_connect($dbhost, $dbusername, $dbpasswd);
mysql_select_db($database_name) or die( "Unable to select database");
$data = mysql_query("SELECT product_name,product_type,ended_date FROM Products ")or die(mysql_error()); ?>
<table>
<tr>
<th>Product Name</th>
<th>Product Type</th>
<th>Product Deadline</th>
<th>Product Details</th>
</tr>
<?php while($info = mysql_fetch_array( $data )) { ?>
<tr>
<td><?php echo $info['product_name'] ?> </td>
<td><?php echo $info['product_type'] ?> </td>
<td><?php echo $info['ended_date'] ?> </td>
<td><?php echo '<a href=view_items.php?> View details</a>'?> </td>
</tr>
<?php } ?>
</table>
2) views_items.php:
<?php
//$product_name = $_POST['product_name'];
include("conf.php");
mysql_connect($dbhost, $dbusername, $dbpasswd);
mysql_select_db($database_name) or die( "Unable to select database");
$data = mysql_query("SELECT Products.product_name, Products.product_type, Products.product_description, Products.ended_date,upload.product_name,upload.content FROM Products, upload where Products.product_name=upload.product_name ")or die(mysql_error());?>
<table>
<tr>
<th>Product Name</th>
<th>Product Type</th>
<th>Product Description</th>
<th>Product Deadline</th>
<th>Product image</th>
</tr>
<?php while($info = mysql_fetch_assoc($data)) { ?>
<tr>
<td><?php echo $info['product_name'] ?> </td>
<td><?php echo $info['product_type'] ?> </td>
<td><?php echo $info['product_description'] ?> </td>
<td><?php echo $info['ended_date'] ?> </td>
<td><img src="<?php
header("Content-type:$type");
echo base64_decode($content);
?>"</td>
</tr>
<?php } ?>
</table> |
ce dernier fichiers me donne que des carres au croix rouge a l'interieur au lieux des images que contienne la table upload. est-ce que quelqu'un peux m'expliquer comment afficher un blob champ d'une Mysql table. Aussi tous comments sur le code ou un autre moyen d'afficher un image a partir d'un fichier ou database serais util pour moi.
je suspecte la partie en rouge apres un debug que j'ai fait, merci vos aides.
Merci d'avance!