Salut,
je suis entrain de développer un site web dynamique d'immobilier sur lequel je dois afficher des images dynamiquement. Pour ce faire, j'ai donc créé une base de données dans laquelle je compte enregistrer les immobiliers avec les informations relatives (par exemple: ville, quartier, titre, description, photo1, photo2, photo3, photo4, photo5, photo6). Cependant je vois que j'ai un soucis avec le chemin. J'ai lu un tuto dans lequel on dit qu'on peut créer soi même son chemin pour l'enregistrement des images, qu'on peut même renommer les images après l'upload pour ne pas garder le nom de depart, mais je ne vois pas malheureusement. Si quelqu'un peu me donner une bonne idée. J'ai quand même essayé mais je n'y parviens pas. Ci-dessus mon code pour améliorations ou si quelqu'un peut me montrer un vrai tuto sur cette partie.
Voici d'abord la page d'insertion
Ensuite la page de traitement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 <?php require_once('header.php'); ?> <!-- Contact Section --> <div id="contact" class="text-center"> <div class="contact-index-header"> <ul class="title section-title"> </br></br></br> <li class="line"></li> <li><h2><b>ENREGISTRER UN IMMOBILIER A VENDRE OU A LOUER</b></h2></li> <li class="line"></li> </ul> <!--<p class="text-muted header-para">liquam porttitor leo non nisl</p> --> </div> <div class="contact-index-body container-fluid"> <div class="container"> <div class="row text-left"> <div class="col-xs-12 col-sm-12 col-sm-12 col-sm-12" id="formulaire"> <form method="post" action="traitement_immobiliers.php" enctype="multipart/form-data" class="form-horizontal"> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-5 col-lg-5"> <label for="ville">Ville</label><br /> <input type="text" name="ville" placeholder="Ville" id="titre" size="30" /> </div> <div class="col-xs-12 col-sm-12 col-md-5 col-lg-5"> <label for="quartier">Quartier</label><br /> <input type="text" name="quartier" value="" id="titre" size="30" /> </div> <div class="col-xs-12 col-sm-12 col-md-2 col-lg-2"> <label for="type">Type d'immobilier</label><br /> <select name="type"> <option value="residence_meublee">Résidence meublée</option> <option value="maison">Maison</option> <option value="terrain">Térrain</option> <option value="terrain">Espace évènementiel</option> <option value="autres">Autres</option> </select> </div> </div> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-7 col-lg-7"> <label for="titre">Titre</label> </br> <input type="text" name="titre" value="" id="titre" size="45" /><br /> </div> <div class="col-xs-12 col-sm-12 col-md-2 col-lg-2"> <label for="statut">Statut</label> </br> <select name="statut"> <option value="location">A louer</option> <option value="vente">A vendre</option> </select> </div> <div class="col-xs-12 col-sm-12 col-md-3 col-lg-3"> <label for="titre">Prix</label> </br> <input type="text" name="prix" value="" id="prix" size="25" /><br/> </div> </div> <div class="row"> <center> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <label for="description"><h2><u>Description de votre bien immobilier (maximum 255 caractères)</u> </h2></label><br /> <textarea name="description" id="description" cols="45" rows="5" ></textarea><br /> </div> </center> </div> <center><h2><u>Sélectionnez les images(JPG, PNG ou GIF | Taille maximale de 2 Mo/image)</u> :</h2></center></br> <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6"> <label for="photo1">IMAGE 1</label> <input type="file" name="photo1" id="icone" size="50" /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> <label for="photo2">IMAGE 2</label> <input type="file" name="photo2" id="icone" size="50" /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> <label for="photo3">IMAGE 3</label> <input type="file" name="photo3" id="icone" size="50" /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> </div> <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6"> <label for="photo4">IMAGE 4</label> <input type="file" name="photo4" id="icone" size="50" /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> <label for="photo5">IMAGE 5</label> <input type="file" name="photo5" id="icone" size="50" /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> <label for="photo6">IMAGE 6</label> <input type="file" name="photo6" id="icone" size="50" /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> </div> <div class="col-xs-12 col-sm-12 col-md-2 col-lg-2"> <div class="text-center"> <input class="btn btn-custom" type="submit" name="envoyer" value="Envoyer" /><i class="fa fa-send-o"></i> </div></br></br></br></br></br></br> <!--<button class="btn btn-custom">Envoyer <i class="fa fa-send-o"></i></button> --> </div> </form> </div> </div> </div> </div> </div></br></br></br></br> <!-- End of Contact Section --> <?php require_once('footer.php'); ?>
L'enregistrement ne se fait pas convenablement. l'affichage non plus.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186 <?php require_once('header.php'); ?> <?php require_once('config.php'); ?> <!-- Contact Section --> <div id="contact" class="text-center"> <!--<div class="contact-index-header"> <ul class="title section-title"> <li class="line"></li> <li><h2>ENREGISTREMENT DE L'IMMOBILIER</h2></li> <li class="line"></li> </ul> <!--<p class="text-muted header-para">liquam porttitor leo non nisl</p> -- </div> --> <div class="contact-index-body container-fluid"> <div class="container"> <div class="row"> <!--<div class="row text-left">--> <div class="col-xs-12 col-sm-12 col-sm-12 col-sm-12"> <center><h2><u>Enregistrement de l'immobilier</u></h2></center> <?php if(isset($_POST['envoyer'])) { if(empty($_POST['ville']) OR empty($_POST['quartier']) OR empty($_POST['type']) OR empty($_POST['titre']) OR empty($_POST['statut']) OR empty($_POST['prix']) OR empty($_POST['description'])) { echo "<center><h3>Remplissez d'abord tous les champs. <a href='immobiliers.php'> Retour à la saisie!</a></h3></center>"; }else { $ville=$_POST['ville']; $quartier=$_POST['quartier']; $type=$_POST['type']; $titre=$_POST['titre']; $statut=$_POST['statut']; $prix=$_POST['prix']; $description=$_POST['description']; // teste de l'envoi du fichier PHOTO 1 if (isset($_FILES['photo1']) and $_FILES['photo1']['error']== 0 ) { // teste de la grandeur de l'image if ($_FILES['photo1']['size'] <= 5242880) { // teste de la prise en compte du chemin et de l'extention du fichier $infosfichier = pathinfo($_FILES['photo1']['name']);//on prend le nom du fichier $extension_upload = $infosfichier['extension']; //on prend l'extension du fichier $extensions_autorisees = array('jpg', 'jpeg', 'gif','png','JPG', 'JPEG', 'GIF','PNG'); //on prend les extensions autorisées if (in_array($extension_upload, $extensions_autorisees)) { move_uploaded_file($_FILES['photo1']['tmp_name'], '../images/photos/'.basename($_FILES['photo1']['name'])); $photo1=$_FILES['photo1']['name']; } } }else{$photo1="../images/photos/.'imagepardefaut.png'";} /* else if (!isset($_FILES['photo1'])) { $req=$bdd->query('SELECT image_par_defaut from engins'); $photo1=$image_par_defaut; $_FILES['photo1']['tmp_name']. '../images/photos/'.basename($_FILES['image_par_defaut']['name']); $photo1=$_FILES['image_par_defaut']['name']; } */ if (isset($_FILES['photo2']) and $_FILES['photo2']['error']== 0 ) { if ($_FILES['photo2']['size'] <= 5242880) { // teste de la prise en compte du chemin et de l'extention du fichier $infosfichier = pathinfo($_FILES['photo2']['name']);//on prend le nom du fichier $extension_upload = $infosfichier['extension']; //on prend l'extension du fichier $extensions_autorisees = array('jpg', 'jpeg', 'gif','png','JPG', 'JPEG', 'GIF','PNG'); //on prend les extensions autorisées if (in_array($extension_upload, $extensions_autorisees)) { move_uploaded_file($_FILES['photo2']['tmp_name'], '../images/photos/'.basename($_FILES['photo2']['name'])); $photo2=$_FILES['photo2']['name']; } } }/* else{echo"Vous n'avez selectionner la photo2 </br>";} */ // teste de l'envoi du fichier if(isset($_FILES['photo3']) and $_FILES['photo3']['error']== 0 ) { if($_FILES['photo3']['size'] <= 5242880) { $infosfichier = pathinfo($_FILES['photo3']['name']); $extension_upload = $infosfichier['extension']; $extensions_autorisees = array('jpg', 'jpeg', 'gif','png','JPG', 'JPEG', 'GIF','PNG'); if(in_array($extension_upload, $extensions_autorisees)) { move_uploaded_file($_FILES['photo3']['tmp_name'], '../images/photos/'.basename($_FILES['photo3']['name'])); $photo3=$_FILES['photo3']['name']; } } } if(isset($_FILES['photo3']) and $_FILES['photo3']['error']== 0 ) { if($_FILES['photo3']['size'] <= 5242880) { $infosfichier = pathinfo($_FILES['photo3']['name']); $extension_upload = $infosfichier['extension']; $extensions_autorisees = array('jpg', 'jpeg', 'gif','png','JPG', 'JPEG', 'GIF','PNG'); if(in_array($extension_upload, $extensions_autorisees)) { move_uploaded_file($_FILES['photo3']['tmp_name'], '../images/photos/'.basename($_FILES['photo3']['name'])); $photo3=$_FILES['photo3']['name']; } } } if(isset($_FILES['photo4']) and $_FILES['photo4']['error']== 0 ) { if($_FILES['photo4']['size'] <= 5242880) { $infosfichier = pathinfo($_FILES['photo4']['name']); $extension_upload = $infosfichier['extension']; $extensions_autorisees = array('jpg', 'jpeg', 'gif','png','JPG', 'JPEG', 'GIF','PNG'); if(in_array($extension_upload, $extensions_autorisees)) { move_uploaded_file($_FILES['photo4']['tmp_name'], '../images/photos/'.basename($_FILES['photo4']['name'])); $photo4=$_FILES['photo4']['name']; } } } if(isset($_FILES['photo5']) and $_FILES['photo5']['error']== 0 ) { if($_FILES['photo5']['size'] <= 5242880) { $infosfichier = pathinfo($_FILES['photo5']['name']); $extension_upload = $infosfichier['extension']; $extensions_autorisees = array('jpg', 'jpeg', 'gif','png','JPG', 'JPEG', 'GIF','PNG'); if(in_array($extension_upload, $extensions_autorisees)) { move_uploaded_file($_FILES['photo5']['tmp_name'], '../images/photos/'.basename($_FILES['photo5']['name'])); $photo5=$_FILES['photo5']['name']; } } } if(isset($_FILES['photo6']) and $_FILES['photo6']['error']== 0 ) { if($_FILES['photo6']['size'] <= 5242880) { $infosfichier = pathinfo($_FILES['photo6']['name']); $extension_upload = $infosfichier['extension']; $extensions_autorisees = array('jpg', 'jpeg', 'gif','png','JPG', 'JPEG', 'GIF','PNG'); if(in_array($extension_upload, $extensions_autorisees)) { move_uploaded_file($_FILES['photo6']['tmp_name'], '../images/photos/'.basename($_FILES['photo6']['name'])); $photo6=$_FILES['photo6']['name']; } } } /* if(empty($photo1) /* OR empty($photo2) OR empty($photo3) *) { $photo1="imageParDefaut.jpg"; } */ // Insertion des données à l'aide d'une requête preparée $req = $bdd->prepare('INSERT INTO immobiliers(ville, quartier, type, titre, statut, prix, description, photo1, photo2, photo3, photo4, photo5, photo6) VALUES(:ville, :quartier, :type, :titre, :statut, :prix, :description, :photo1, :photo2, :photo3, :photo4, :photo5, :photo6)'); /* var_dump($photo2); */ /*echo '<!--'; Ceci permet de masquer les erreurs PHP*/ $req->execute(array(':ville'=>$_POST['ville'], ':quartier'=>$quartier, ':type'=>$type, ':titre'=>$titre, ':statut'=>$statut, ':prix'=>$prix, ':description'=>$description, ':photo1'=>$photo1, ':photo2'=>$photo2, ':photo3'=>$photo3, ':photo4'=>$photo4, ':photo5'=>$photo5, ':photo6'=>$photo6)) or die (print_r($req->errorInfo())); /*echo '-->'; Ceci permet de masquer les erreurs PHP*/ if ($req) { echo "Enregistrement effectué avec succès <a href='immobiliers.php'>Faire un nouvel enregistrement</a>"; } else { echo 'Mauvais enregistrement!'; } } } ?> </div> </div> </div> </div> </div> <!-- End of Contact Section --> <?php require_once('footer.php'); ?>
Voici la page d'affichage des enregsitrements
Merci pour toutes aides!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 <?php include ('config.php');?> <?php $enginParPage=5; //Nous allons afficher 5 messages par page. //Une connexion SQL doit être ouverte avant cette ligne... $retour_total=$bdd->query('SELECT COUNT(*) AS total FROM immobiliers'); //Nous récupérons le contenu de la requête dans $retour_total $donnees_total=$retour_total->fetch(PDO::FETCH_ASSOC); $total=$donnees_total['total']; //On récupère le total pour le placer dans la variable $total. //Nous allons maintenant compter le nombre de pages. $nombreDePages=ceil($total/$enginParPage); if(isset($_GET['page'])) // Si la variable $_GET['page'] existe... { $pageActuelle=intval($_GET['page']); if($pageActuelle>$nombreDePages) // Si la valeur de $pageActuelle (le numéro de la page) est plus grande que $nombreDePages... { $pageActuelle=$nombreDePages; } } else { $pageActuelle=1; // La page actuelle est la n°1 } $premiereEntree=($pageActuelle-1)*$enginParPage; // On calcul la première entrée à lire // La requête sql pour récupérer les messages de la page actuelle. $req_retour_engins=$bdd->query('SELECT * FROM immobiliers ORDER BY id DESC LIMIT '.$premiereEntree.', '.$enginParPage.''); while($donnees = $req_retour_engins->fetch(PDO::FETCH_ASSOC)) { echo'<table border="0px"; width:800px; height:500px; color="#FFFFFF";> <tr> <td class="description"> <a href="operation.php?id='.$donnees['id'].'"> <img src="images/photos/'.$donnees['photo1'].'"style=" width:220px; height:150px; color="#FFFFFF"; /></a></br></br> </td> <td class="description"> <a href="operation.php?id='.$donnees['id'].'"> Numero: '.htmlentities($donnees['id']).'</br>Ville: '.htmlentities($donnees['ville']).'</br>Quartier: '.$donnees['quartier'].'</br>Type de bien: '.$donnees['type'].'</br>Titre: ' .$donnees['titre'].'</br>Statut: '.$donnees['statut'].'</br>Prix: '.$donnees['prix'].'</br>Description: '.$donnees['description'].' </a> </td> </tr> </table>'; echo '<a href="operation.php?id='.$donnees['id'].'"> Reserver </a> '; echo '<a href="admin/details.php?id='.$donnees['id'].'"> Visualiser </a></br></br>'; } $req_retour_engins->closeCursor(); echo'</br>'; echo '<center><p align="center"><b><b>Page :</b></b> '; //Pour l'affichage, on centre la liste des pages for($i=1; $i<=$nombreDePages; $i++) //On fait notre boucle { //On va faire notre condition if($i==$pageActuelle) //Si il s'agit de la page actuelle... { echo '<b><b> [ '.$i.' ] </b></b>'; } else { echo ' <a href="index.php?page='.$i.'">'.$i.'</a> '; } } echo '</p></center>'; ?>
Partager