Précédent   Forum des professionnels en informatique > Bases de données > MySQL > Débuter
Débuter Forum d'entraide pour débuter avec MySQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 16/04/2008, 15h56   #1
Invité de passage
 
Inscription : avril 2008
Messages : 1
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 1
Points : 0
Points : 0
Par défaut 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']  ?>&nbsp;&nbsp;&nbsp;</td>
  <td><?php echo $info['product_type']  ?>&nbsp;&nbsp;&nbsp;</td>
  <td><?php echo $info['ended_date']  ?>&nbsp;&nbsp;&nbsp;</td>
  <td><?php echo '<a href=view_items.php?> View details</a>'?>&nbsp;&nbsp;&nbsp;</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']  ?>&nbsp;&nbsp;&nbsp;</td>
  <td><?php echo $info['product_type']  ?>&nbsp;&nbsp;&nbsp;</td>
  <td><?php echo $info['product_description']  ?>&nbsp;&nbsp;&nbsp;</td>
  <td><?php echo $info['ended_date']  ?>&nbsp;&nbsp;&nbsp;</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!
ilyazi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/04/2008, 20h58   #2
Membre expérimenté
 
Étudiant
Inscription : mars 2006
Messages : 396
Détails du profil
Informations personnelles :
Localisation : France, Nord (Nord Pas de Calais)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : mars 2006
Messages : 396
Points : 500
Points : 500
En fait, tu étais proche de la solution.
Le code affichant l'image doit se trouver dans un fichier indépendant.
Code html :
1
2
3
// views_items.php
 
<img src="view_image.php?id">
id correspond à l'identifiant d'une image.

Code php :
1
2
3
4
5
// view_image.php
 
header("Content-type:$type");
// ... code affichant l'image ...
echo base64_decode($content);
jeremya est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/04/2008, 09h08   #3
Membre Expert
 
Avatar de Jumano
 
Inscription : février 2007
Messages : 1 162
Détails du profil
Informations personnelles :
Âge : 43
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : février 2007
Messages : 1 162
Points : 1 369
Points : 1 369
Bonjour,
Pourquoi ne pas faire simplement ceci :
Code :
<td><img src="<?php echo $info['content']  ?>" /></td>
Citation:
Envoyé par ilyazi Voir le message
... fichiers me donne que des carres au croix rouge a l'interieur au lieux des images que contienne la table upload.
Vérifie bien le lien vers tes images que tu as dans ta base ... par rapport à ta page "views_items.php"
Jumano est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 15h39.


 
 
 
 
Partenaires

Hébergement Web