salut j'ai des fichiers ou image dans ma base de donnée que je veux afficher à l'aide d'une requête php mais j'arrive pas.
je vous redonne mes différents fichiers pour que vous apportez votre appréciation.
choix_fichier.html
Code HTML :
<!--choix_fichier.html-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<table width="200" border="0" align="center">
<tr>
<td><form action="./upload.php" method="post" enctype="multipart/form-data" name="formulaire_envoi_fichier" id="formulaire_envoi_fichier">
<input type="file" name="fichier_choisi" />
<br />
<br />
<input type="submit" name="bouton_submit" value="Envoyer le fichier" />
</form></td>
</tr>
</table>
</body>
</html>
upload.php
Code PHP :
<?php
/*ceci est upload php*/
/*transfert du fichier client vers le repertoire du serveur*/
//on vérifies que le champ est bien rempli:
if(!empty($_FILES["fichier_choisi"]["name"]))
{
//nom du fichier choisi:
$nomFichier = $_FILES["fichier_choisi"]["name"] ;
//nom temporaire sur le serveur:
$nomTemporaire = $_FILES["fichier_choisi"]["tmp_name"] ;
//type du fichier choisi:
$typeFichier = $_FILES["fichier_choisi"]["type"] ;
//poids en octets du fichier choisit:
$poidsFichier = $_FILES["fichier_choisi"]["size"] ;
//code de l'erreur si jamais il y en a une:
$codeErreur = $_FILES["fichier_choisi"]["error"] ;
//chemin qui mène au dossier qui va contenir les fichiers uplaod:
$chemin = "./upload_fichier/" ;
if(copy($nomTemporaire, $fichier_choisi = $chemin.$nomFichier))
echo("<br>l'upload a réussi : <hr ><img src=\"".$fichier_choisi."\">") ;
else
echo("<br>l'upload a échoué") ;
}//fin if
else
{
echo("Vous n'avez pas choisit de fichier!!<br>") ;
echo("<a href=\"./choix_fichier.html\">Retour</a>") ;
}//fin else
/*partie sql insertion du chemin*/
if(isset($_POST["bouton_submit"])) {
//$_POST["fichier_choisi"]="";
//$statut = $_POST['fichier_choisi'];
/*a personnaliser ton serveur ta base ...*/
$db = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('DirectVictime',$db) or die(mysql_error());
/*on insere le chemin vers le ficihier uploade*/
// on fait l'INSERT dans la base de données
$sql= "INSERT INTO renseigner (fichier_choisi) VALUES ('$fichier_choisi')";
$result = mysql_query($sql) or die(mysql_error());
if (!$result) {
die('linsertion n a pas réussie !!! : ' . mysql_error());
}
//header("Location:renseignement.php?add=ok"); // redirection si création réussie
} else {
// form pas submit
}
?>
req_fichier.php
Code PHP :
<?php
$_POST["fichier_choisi"]="";
// $nom1=trim($_POST["fichier_choisi"]);
$color=array('#333333','#999999');
$i=0;
// Connexion à la BDD
mysql_connect("localhost","root","") or die("erreur de connexion");
// Sélection de la base de données
mysql_select_db("DirectVictime") or die("Erreur de selection de la BD");
/*faut securiser*/
// on crée la requête SQL
$sql = "SELECT fichier_choisi FROM renseigner
WHERE id='5'";
// on envoie la requête
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$res = mysql_num_rows($req); // 4
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
<style type="text/css">
<!--
.Style3 {color: #FFFFFF}
.Style6 {
color: #0000FF;
font-style: italic;
font-weight: bold;
}
-->
</style>
</head>
<body>
<div align="center">
<h1 align="center" class="Style6">>>> IMAGE DE LA VICTIMES DE GUERRE EN COTE D'IVOIRE <<< </h1>
</div>
<p> </p>
<table width="451" border="0" align="center" cellspacing="2" bgcolor="#00FF00">
<tr bgcolor="#999999">
<th bgcolor="#FF00FF" scope="row"><div align="left"><A HREF="enregistrement.php" TITLE="click pour enregistrer vos enfants!!! !!!!" class="Style17 Style3"><strong>Accueil</strong></a></div></th>
</tr>
<tr bgcolor="#999999">
<th width="206" scope="row"><span class="Style3">PHOTO </span></th>
</tr>
<?php
while ($liste_etu=mysql_fetch_assoc($req)) {
$j=$i%2;
?>
<tr bgcolor=#33FFFF>
<td><?php echo $liste_etu['fichier_choisi'] ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>