Je tiens à préciser que sa fait 3 jours que j’essaie d'envoyer (uploader) une Photo en local, j'arrive à le faire avec mon fichier upload.php mais pas en l'intégrant dans mon formulaire.
J'ai fait de nombreux test et recherche sur différents forum, mais je n'y arrive toujours pas.
J'ai un formulaire avec les variables : nom, adresse, CP, Ville etc ... et Photo que j'envoie dans une base MySQL.
Ça fonctionne bien, mais pas le transfert de la "Photo".
J'ai 2 fichiers
1). modifier.php
2). modifier_valider.php<?php echo '<form action="modifier_valider.php?Photo='.$photo.'" method="POST" class="form" enctype="multipart/form-data" />'; echo "<table align='center' class='liste'>"; echo "<tr>"; echo "<td>Num identifiant</td>"; echo "<td>" . $id ."</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Num</td>"; echo "<td><input type='text' value='$num_adresse' name='num_adresse'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Adresse</td>"; echo "<td><input type='text' value='$adresse' name='Adresse'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>CP</td>"; echo "<td><input type='text' value='$bien_cp' name='CP_bien'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>ville</td>"; echo "<td><input type='text' value='$ville' name='Ville'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Détail</td>"; echo "<td><input type='text' value='$detail' name='Detail'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Sindyc</td>"; echo "<td><input type='text' value='$str_bien_syndic' name='Syndic_bien'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Relance</td>"; echo "<td>\"$date\"</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Photo</td>"; echo '<td align="center"><img src="vignette/'.$photo.'" width="24" height="18" name="Vignette" /></td>'; echo "</tr>"; echo "<tr>"; echo "<td>Photo</td>"; echo "<td>"; echo ' <input type="file" value='.$photo.' name="Photo" class="form" > <input type="hidden" value='.$photo.' name="Photo" class="form" /> <br /><br />'; // $bien_Photo = $_GET['Photo']; if (!isset($_GET['Photo'])) { $idir = "photo/"; $tdir = "vignette/"; $twidth = "50"; $theight = "40"; } else if (isset($_GET['photo']) && $_GET['photo'] == 'Photo') { $url = $_FILES['Photo']['name']; if ($_FILES['Photo']['type'] == "image/jpg" || $_FILES['Photo']['type'] == "image/jpeg" || $_FILES['Photo']['type'] == "image/pjpeg" ) { $file_ext = strrchr($_FILES['Photo']['name'], '.'); $copy = copy($_FILES['Photo']['tmp_name'], "$idir" . $_FILES['Photo']['name']); if ($copy) { print ' L\'image a été téléchargé avec succès.<br />'; // A réussi à télécharger l'image $simg = imagecreatefromjpeg("$idir" . $url); $currwidth = imagesx($simg); $currheight = imagesy($simg); if ($currheight > $currwidth) { $zoom = $twidth / $currheight; $newheight = $theight; $newwidth = $currwidth * $zoom; } else { $zoom = $twidth / $currwidth; $newwidth = $twidth; $newheight = $currheight * $zoom; } $dimg = imagecreate($newwidth, $newheight); imagetruecolortopalette($simg, false, 256); $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { $colors = ImageColorsForIndex($simg, $i); ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); imagejpeg($dimg, "$tdir" . $url); imagedestroy($simg); imagedestroy($dimg); print 'La vignette a été créé avec succès.'; // Redimensionnement réussi } else { print '<font color="#FF0000"> ERREUR: Impossible de télécharger l\'image. </font>'; // Message d'Erreur lors d'un Échec du transfert du fichier } } else { print '<font color="#FF0000">ERREUR: Mauvais Type de fichier (vérifiez que le format (l\'extention) soit en .jpg ou .jpeg ou .png . '; // Message d'erreur si le Type de fichier est Mauvais print $file_ext; print '.</font>'; } } echo "</tr>"; echo "<tr> <td>Notes</td> <td><textarea type='longtext' style='width:320px; height:150px;' heigth='30' width='50' cols='1' rows='1' value='$notes' name='notes'/></textarea></td> </tr>"; echo "<tr>"; echo "<td>Actions</td>"; echo "<td>"; echo '<input type="submit" value="Modifier" class="form" />'; echo "</td>"; echo "</tr>"; echo "</table>"; echo "<input type='hidden' value=".$id." name='id'>"; echo "</form>"; ?>
<?php // ACCES A LA BASE DE DONNEE include "config.php"; // Rendre la base de données foo, la base courante $db_selected = mysql_select_db($sql_bd, $sqllink); if (!$db_selected) { die ('Impossible de sélectionner la base de données : ' . mysql_error()); } $id= $_GET['id']; $num_adresse = $_POST['num_adresse']; $adresse = $_POST['Adresse']; $cp = $_POST['CP']; $ville = $_POST['Ville']; $detail = $_POST['Detail']; $notes = $_POST['notes']; $date = $_POST['date']; $photo = $_POST['Photo']; $prop_ID = $_POST['prop_ID']; $sql_query = "UPDATE $sql_tbb SET num_adresse='".$num_adresse."', Adresse_bien='".$adresse."', CP='".$cp."', Ville='".$ville."', Detail='".$detail."', notes='".$notes."', date='".$date."', Photo='".$photo."', prop_ID='".$prop_ID."' WHERE id='".$id."' "; $result = mysql_query($sql_query); if (!$result) { echo 'Impossible d\'exécuter la requête : ' . mysql_error(); exit; } else { echo "Le bien a été mis a jour $sql_query "; } echo "l'image ".$photo." a bien été récupéré . "; echo '<a href="detail.php?id='.$id.'">retour</a>'; mysql_close($sqllink); ?>