Bonjour,
Comme vous vous en doutez je poste ce message car j'ai un problème, en effet je tente de créer une page qui permettra l'upload d'un fichier, j'ai donc repris les codes d'un autre site dans lequel cela fonctionne parfaitement et j'ai effectué les modifications nécessaires (nom des variables, adresse de dossiers,...), mais ça ne fonctionne pas.
Cela quelques semaines que je me rechercher, que je relis mon code, mais rien n'y fais, j'ai testé l'insertion des infos sans le fichier à uploader cela fonctionne bien, donc le problème vient du code d'upload mais je ne trouve pas l'erreur.
Je vous fais parvenir les 2 codes, celui du formulaire "ajout_ad.php" et celui du traitement "ajout_ad2.php"
ajout_ad.php :
ajout_ad2.php :
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 <?php include("include/bdd.inc.php"); ?> <!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=utf-8" /> <title>AJOUT - ADHERENTS</title> <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" /> <!--<link rel="icon" type="image/jpg" href="images/favicon.jpg">--> <link href="css/reset.css" rel="stylesheet" type="text/css" /> <link href="css/menu.css" rel="stylesheet" type="text/css" /> <link href="css/design.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="contains"> <?php include("include/inc_header.php"); ?> <?php include("include/inc_menu.php"); ?> <div id="page" class="bor_general"> <div id="corps"> <div id="tit_corps"> <h2 class="gen">AJOUT D'ADHERENTS</h2> <div class="clear"></div> </div> <form method="post" action="ajout_ad2.php" id="form" enctype="multipart/form-data" > <table> <tr> <td width="120" class="tit_champ">NOM :</td> <td width="600"><input name="ad_nom" type="text" id="nom" class="txt_champ" /></td> </tr> <tr> <td width="119" class="tit_champ">ADRESSE :</td> <td width="423"><input name="ad_adresse" type="text" id="adresse" class="txt_champ" /></td> </tr> <tr> <td width="119" class="tit_champ">SITE :</td> <td width="423"><input name="ad_site" type="text" id="site" class="txt_champ" /></td> </tr> <tr> <td width="119" class="tit_champ">LOGO* :</td> <td class="champfichier"><input type="hidden" name="MAX_FILE_SIZE" value="1000000" /><input name="avatar" type="file" /></td> </tr> <tr> <td width="119" class="tit_champ">ACTIF</td> <td class="champfichier"><input name="actif" type="checkbox" id="actif" /></td> </tr> <tr> <td> </td> <td><input name="envoyer" type="image" src="design/envoyer.png" value="envoyer" /></td> </tr> </table> </form> <p>* fichier ".png" - dimension : 200x150</p> <div class="clear"></div> </div> <div id="bandeau"> <?php include("include/inc_bandeau_droit.php"); ?> </div> </div> <div class="clear"></div> </div> <?php include("include/inc_footer.php"); ?> </div> <!--<div id="coprs"> <div id="tit_corps"> <h2 class="gen">LISTE DES ADHERENTS</h2> <table width="680" border="0 "> <tr> <td width="30" class="tit_tab">N°</td> <td width="150" class="tit_tab">NOM</td> <td width="200" class="tit_tab">ADRESSE</td> <td width="100" class="tit_tab">SITE</td> <td width="120" class="tit_tab">LOGO</td> <td width="50" class="tit_tab">Actif</td> <td width="30" class="tit_tab">Sup.</td> </tr> <?php $reponse = $bdd->query('SELECT * FROM adherents ORDER BY ad_nom'); while ($donnees = $reponse->fetch()) { ?> <tr> <td class="result_tab"><?php echo htmlspecialchars($donnees['id']); ?></td> <td class="result_tab"><?php echo htmlspecialchars($donnees['ad_nom']); ?></td> <td class="result_tab"><?php echo htmlspecialchars($donnees['ad_adresse']); ?></td> <td class="result_tab"><?php echo htmlspecialchars($donnees['ad_site']); ?></td> <td class="result_tab"><?php echo htmlspecialchars($donnees['ad_logo']); ?></td> <td class="result_tab"><?php echo htmlspecialchars($donnees['actif']); ?></td> <td class="result_tab"><a href="javascript:if(confirm('Etes-vous sûr de vouloir supprimer cet adhérent : <?php echo addslashes($donnees['ad_nom']); ?> ?')){document.location.href='suppr_ad.php?id=<?php echo $donnees['id']; ?>';}">S</a></td> </tr> <?php } $reponse->closeCursor(); ?> </table> <p> Pour ajouter un nouveau "adherent" : <a href="ajout_ad.php">CLIQUEZ ICI</a></p> </div> <div class="clear"></div> </div> <div id="bandeau"> <?php include("include/inc_bandeau_droit.php"); ?> </div> </div> <?php include("include/inc_footer.php"); ?> </div>--> <!-- Start of StatCounter Code for Dreamweaver --> <script type="text/javascript"> var sc_project=9784985; var sc_invisible=1; var sc_security="c3caf157"; var scJsHost = (("https:" == document.location.protocol) ? "https://secure." : "http://www."); document.write("<sc"+"ript type='text/javascript' src='" + scJsHost+ "statcounter.com/counter/counter.js'></"+"script>"); </script> <noscript><div class="statcounter"><a title="web analytics" href="http://statcounter.com/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/9784985/0/c3caf157/1/" alt="web analytics"></a></div></noscript> <!-- End of StatCounter Code for Dreamweaver -- </body> </html>
D'avance merci de vos retours,
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("include/bdd.inc.php"); ?> <?php function filter($in) { $search = array ('@[éèêëÊË]@i','@[àâäÂÄ]@i','@[îïÎÏ]@i','@[ûùüÛÜ]@i','@[ôöÔÖ]@i','@[ç]@i','@[ ]@','@[\']@'); $replace = array ('e','a','i','u','o','c','_',''); return preg_replace($search, $replace, $in); } $ad_nom=htmlspecialchars($_POST["ad_nom"]); $ad_adresse=htmlspecialchars($_POST["ad_adresse"]); $ad_site=htmlspecialchars($_POST["ad_site"]); if(isset($_POST["actif"])){ echo $actif=1 ; } else { echo $actif=0; } if(isset($_FILES['ad_logo'])) { $dossier = 'images/adherents/'; echo "<br>" .$dossier; $ad_logo = basename($_FILES['ad_logo']['name']);echo "<br>" . $_FILES['ad_logo']['tmp_name']; $taille_maxi = 1000000; $taille = $_FILES['ad_logo']['size']; $extensions = array('.png'); $extension = $_FILES['ad_logo']['type']; //Début des vérifications de sécurité... if(!file_exists($dossier)){ echo "<br> Erreur le dossier $dossier n'existe pas !"; } if(!in_array($extension, $extensions)) //Si l'extension n'est pas dans le tableau { $erreur = '<br> Vous devez uploader un fichier de type png...'; } if($taille>$taille_maxi) { $erreur = '<br> Le fichier est trop gros...'; } if(!isset($erreur)) //S'il n'y a pas d'erreur, on upload { //On formate le nom du fichier ici... $ad_logo = strtr($ad_logo, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy'); $ad_logo = preg_replace('/([^.a-z0-9]+)/i', '-', $ad_logo); if(move_uploaded_file($_FILES['ad_logo']['tmp_name'], $dossier . $ad_logo)) //Si la fonction renvoie TRUE, c'est que ça a fonctionné... { echo '<br> Upload a IMAGE effectué avec succès !'; } else //Sinon (la fonction renvoie FALSE). { echo '<br> Echec de l\'upload IMAGE !';echo "<br> chemin de destination =>" . $dossier . $ad_logo; } } else { echo $erreur; } $req = $bdd->prepare('INSERT INTO adherents(ad_nom, ad_adresse, ad_site, ad_logo, actif) VALUES (:ad_nom, :ad_adresse, :ad_site, :ad_logo, :actif)'); $req->execute(array( 'ad_nom' => $ad_nom, 'ad_adresse' => $ad_adresse, 'ad_site' => $ad_site, 'ad_logo' => $ad_logo, 'actif' => $actif )); //header("location:liste_adherents.php"); } ?>
Partager