PHP Récupérer une image d'un formulaire
Résolu
JBennn
Messages postés
92
Date d'inscription
Statut
Membre
Dernière intervention
-
yoyo -
yoyo -
Bonjour,
Encore un problème..
Voila j'ai un formulaire qui enregistre les données saisies par l'utilisateur dans une base de donnée et ensuite qui affiche sur une autre page dans un tableau. Mais je n'arrive pas à afficher l'image.. sa me mets un petit carré cassé en deux. Pouvez-vous m'aider ?
Voici mes codes :
Formulaireajout.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Formulaire</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="Miseenforme" href="Miseenforme.css" />
</head>
<body>
<div id="corps">
<form action="creation.php" method="post" enctype="multipart/form-data">
<table border="0" align="center" cellspacing="2" cellpadding="2">
<tr align="center">
<td>Titre</td>
<td><input type="text" name="Titre"/></td>
</tr>
<tr align="center">
<td>Date</td>
<td><input type="date" name="Date"/></td>
</tr>
<tr align="center">
<td>Description</td>
<td><input type="text" name="Description"/></td>
</tr>
<tr align="center">
<td>Lien</td>
<td><input type="text" name="Lien"/><br/>
</tr>
<tr align="center">
<td>Image</td>
<td><input type="file" name="Image"><br/>
</tr>
<tr align="center">
<td>Location</td>
<td><input type="text" name="Location"><br/>
</tr>
<tr align="center">
<td>Lien Vidéo</td>
<td><input type="text" name="LienVideo"><br/><br/>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" /> <input type="reset"/> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
et creation.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title> Envoie des données </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="Miseenforme" href="Miseenforme.css" />
</head>
<body>
<p>
<?php
$cnx=mysql_connect("localhost","root","")or die("Erreur de connexion au serveur");
$db=mysql_select_db("stagecddp")or die ("Erreur de connexion à la base stagecddp");
$Titre=$_POST['Titre'];
$Date=$_POST['Date'];
$Description=$_POST['Description'];
$Lien=$_POST['Lien'];
$Image= $_FILES['Image']['name'] ;
$Location=$_POST['Location'];
$LienVideo=$_POST['LienVideo'];
// Lien
$verif_url = strtolower($Lien);
$verif_url = substr("$verif_url", 0, 7);
// Lien Vidéo
if ($verif_url!="http://")
{
print("Le Lien doit commencer par <b>http://</b>");
exit();
}
$verif_url = strtolower($LienVideo);
$verif_url = substr("$verif_url", 0, 7);
if ($verif_url!="http://")
{
print("Le LienVideo doit commencer par <b>http://</b>");
exit();
}
if (isset( $_FILES['file'])){
if ($_FILES['file']['size'] <= 9999999999999){
$infosfichier = pathinfo($_FILES['file']['name']);
$extension_upload = $infosfichier['extension'];
$extensions_autorisees = array('jpg', 'jpeg', 'gif', 'png');
if (in_array($extension_upload, $extensions_autorisees)){
$repertoire= "./Images/";
move_uploaded_file($_FILES['file']['tmp_name'],$repertoire.$_FILES['file']['name']);
echo "L'envoi a bien été effectué !";
$requete =" INSERT INTO formulaire VALUE ('NULL', '".$Image."')";
$result = mysql_query( $requete);
}
}
}
$MonSql="INSERT INTO formulaire(Titre, Date, Description, Lien, Image, Location, LienVideo) VALUES('$Titre','$Date','$Description', '$Lien', '$Image','$Location','$LienVideo')";
$requete=mysql_query($MonSql, $cnx) or die ( mysql_error() );
if($requete)
{
echo ("L'insertion a été correctement effectué");
}
else
{
echo("L'insertion a échoué");
}
?>
<table border="4" color="black">
<caption>Fiche</caption>
<thead>
<tr border="5">
<th>Titre</th>
<th>Date</th>
<th>Description</th>
<th>Lien</th>
<th>Image </th>
<th>Location</th>
<th>Lien vidéo</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $_POST['Titre']; ?></td>
<td><?php echo $_POST['Date']; ?></td>
<td><?php echo $_POST['Description']; ?></td>
<td><?php echo $_POST['Lien']; ?></td>
<td><?php echo'<img src="Images/" >'; ?></td>
<td><?php echo $_POST['Location']; ?></td>
<td><?php echo $_POST['LienVideo']; ?></td>
</tr>
</tbody>
</table><br/>
<h3><a href="modification1.php"> Modifier un évènement </a></h3> <h3><a href="suppression1.php"> Supprimer un évènement </a></h3>
</p>
</body>
</html>
Encore un problème..
Voila j'ai un formulaire qui enregistre les données saisies par l'utilisateur dans une base de donnée et ensuite qui affiche sur une autre page dans un tableau. Mais je n'arrive pas à afficher l'image.. sa me mets un petit carré cassé en deux. Pouvez-vous m'aider ?
Voici mes codes :
Formulaireajout.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>Formulaire</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="Miseenforme" href="Miseenforme.css" />
</head>
<body>
<div id="corps">
<form action="creation.php" method="post" enctype="multipart/form-data">
<table border="0" align="center" cellspacing="2" cellpadding="2">
<tr align="center">
<td>Titre</td>
<td><input type="text" name="Titre"/></td>
</tr>
<tr align="center">
<td>Date</td>
<td><input type="date" name="Date"/></td>
</tr>
<tr align="center">
<td>Description</td>
<td><input type="text" name="Description"/></td>
</tr>
<tr align="center">
<td>Lien</td>
<td><input type="text" name="Lien"/><br/>
</tr>
<tr align="center">
<td>Image</td>
<td><input type="file" name="Image"><br/>
</tr>
<tr align="center">
<td>Location</td>
<td><input type="text" name="Location"><br/>
</tr>
<tr align="center">
<td>Lien Vidéo</td>
<td><input type="text" name="LienVideo"><br/><br/>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" /> <input type="reset"/> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
et creation.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title> Envoie des données </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="Miseenforme" href="Miseenforme.css" />
</head>
<body>
<p>
<?php
$cnx=mysql_connect("localhost","root","")or die("Erreur de connexion au serveur");
$db=mysql_select_db("stagecddp")or die ("Erreur de connexion à la base stagecddp");
$Titre=$_POST['Titre'];
$Date=$_POST['Date'];
$Description=$_POST['Description'];
$Lien=$_POST['Lien'];
$Image= $_FILES['Image']['name'] ;
$Location=$_POST['Location'];
$LienVideo=$_POST['LienVideo'];
// Lien
$verif_url = strtolower($Lien);
$verif_url = substr("$verif_url", 0, 7);
// Lien Vidéo
if ($verif_url!="http://")
{
print("Le Lien doit commencer par <b>http://</b>");
exit();
}
$verif_url = strtolower($LienVideo);
$verif_url = substr("$verif_url", 0, 7);
if ($verif_url!="http://")
{
print("Le LienVideo doit commencer par <b>http://</b>");
exit();
}
if (isset( $_FILES['file'])){
if ($_FILES['file']['size'] <= 9999999999999){
$infosfichier = pathinfo($_FILES['file']['name']);
$extension_upload = $infosfichier['extension'];
$extensions_autorisees = array('jpg', 'jpeg', 'gif', 'png');
if (in_array($extension_upload, $extensions_autorisees)){
$repertoire= "./Images/";
move_uploaded_file($_FILES['file']['tmp_name'],$repertoire.$_FILES['file']['name']);
echo "L'envoi a bien été effectué !";
$requete =" INSERT INTO formulaire VALUE ('NULL', '".$Image."')";
$result = mysql_query( $requete);
}
}
}
$MonSql="INSERT INTO formulaire(Titre, Date, Description, Lien, Image, Location, LienVideo) VALUES('$Titre','$Date','$Description', '$Lien', '$Image','$Location','$LienVideo')";
$requete=mysql_query($MonSql, $cnx) or die ( mysql_error() );
if($requete)
{
echo ("L'insertion a été correctement effectué");
}
else
{
echo("L'insertion a échoué");
}
?>
<table border="4" color="black">
<caption>Fiche</caption>
<thead>
<tr border="5">
<th>Titre</th>
<th>Date</th>
<th>Description</th>
<th>Lien</th>
<th>Image </th>
<th>Location</th>
<th>Lien vidéo</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $_POST['Titre']; ?></td>
<td><?php echo $_POST['Date']; ?></td>
<td><?php echo $_POST['Description']; ?></td>
<td><?php echo $_POST['Lien']; ?></td>
<td><?php echo'<img src="Images/" >'; ?></td>
<td><?php echo $_POST['Location']; ?></td>
<td><?php echo $_POST['LienVideo']; ?></td>
</tr>
</tbody>
</table><br/>
<h3><a href="modification1.php"> Modifier un évènement </a></h3> <h3><a href="suppression1.php"> Supprimer un évènement </a></h3>
</p>
</body>
</html>
A voir également:
- PHP Récupérer une image d'un formulaire
- Whatsapp formulaire opposition - Guide
- Comment recuperer un message supprimé sur whatsapp - Guide
- Formulaire de réclamation facebook compte désactivé - Guide
- Comment recuperer une video sur youtube - Guide
- Comment récupérer un compte facebook piraté - Guide
5 réponses
D'accord j'essaierai après car là gros problème quand je clique sur start pour lancer appache.. cela reste 2 secondes sur stop et ensuite ça remet "start"... je peux donc pas travailler mon php et ma base de données ..
<td><?php echo'<img src="Images/" >'; ?></td>
---> A première vue tu n'as pas renseigné d'image, donc c'est normal.
---> A première vue tu n'as pas renseigné d'image, donc c'est normal.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
D'après ce que je vois de ton code, tu upload ton image dans le dossier Images, tu sauvegarde le nom de ton image dans ta base de données, et tu affiches ensuite le tout. Tu fais ça dans creation.php.
Donc moi je ferais:
<td><?php echo'<img src="Images/"'.$Image." >'; ?></td>
La valeur de $Image va être remplacée par le nom de ton image, genre img1.png. Ton src aura donc pour valeur Images/img1.png, et là il trouvera bien l'image.
Donc moi je ferais:
<td><?php echo'<img src="Images/"'.$Image." >'; ?></td>
La valeur de $Image va être remplacée par le nom de ton image, genre img1.png. Ton src aura donc pour valeur Images/img1.png, et là il trouvera bien l'image.