Afficher un image d'un champ BLOB
Bonjour,
J'ai essayé d'adapter un script trouvé sur ce site, sans succès.
http://beaussier.developpez.com/arti...hp/mysql/blob/
Il y a certainement une erreur grossière, mais je n'arrive pas à mettre le doigt dessus et l'image ne s'affiche jamais. Merci d'avance pour votre aide:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?php
include ("dbconnect.php");
if ($id) {
$result = mysql_query("SELECT * FROM modeles WHERE noModele=$id",$db);
$row = mysql_fetch_array($result);
.....
$id = $row["noModele"];
$cs = $row["cascades"];
$prix = $row["prix"];
echo "Cascades: $cs<br>";
echo "Prix: $prix<br>";
echo "<img src='product_image.php?id=$id'>";
} else {
echo "Veuillez sélectionner un enregistrement";
}
?> |
contenu du fichier product_image.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
| <?php
if ( isset($_GET['id']) )
{
$id = intval ($_GET['id']);
include("include/dbconnect.php");
$req = "SELECT img_id, img_type, img_blob ".
"FROM images WHERE img_id = ".$id;
$ret = mysql_query ($req) or die (mysql_error ());
$col = mysql_fetch_row ($ret);
if ( !$col[0] )
{
echo "Id d'image inconnu";
}
else
{
header ("Content-type: ".$col[1]);
echo $col[2];
}
}
else
{
echo "Mauvais id d'image";
}
?> |