Afficher une image depuis ma base de données MySQL
bonjour
j'ai trouvé un code pour afficher une image depuis ma base de données Mysql de phpMyAdmin, mais celà m'affiche du charabia et en plus j'ai un méssage du type "Cannot modify header information - headers already ....."
je liste mes images avec ce code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
<?php
include ("connexion.php");
$req = "SELECT img_nom, img_id ".
"FROM images ORDER BY img_nom";
$ret = mysql_query ($req) or die (mysql_error ());
while ($col = mysql_fetch_row ($ret) )
{
echo "<a href=\"apercu.php?id=".$col[1].
"\">".$col[0]."</a><br/>";
}
?> |
et je les affiches avec celui-ci:
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
|
<?php
if ( isset($_GET['id']) )
{
$id = intval ($_GET['id']);
include ("connexion.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";
}
?> |
aidez moi s'il vous plait.