Bonjour à tous.

je souhaite faire une barre de progression d'upload. Le souci c'est qu'après pas mal de recherche je ne sais pas comment l'implanter. J'ai regardé fannyupload, mais je n'arrive pas à le mettre en place. Je passe mon code d'upload.

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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
 
include "connec.inc.php";
 
if(isset($_POST['insert']))
{
 
$accent='ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËéèêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ'; 
$noaccent='AAAAAAAAAAAAOOOOOOOOOOOOEEEEEEEECCIIIIIIIUUUUUUUYNN'; 
 
/*echo "<pre>";
var_dump($_FILES);
echo "</pre>";*/
 
	 if ($_POST['commune']=="" or empty($_POST['cbTheme']) or empty($_FILES['fichier']['name']))
	 {
	 	$msg = "Une photo doit être absolument affectée à une commune et au moins 1 thème. N'oubliez pas de sélectionner une photo.";
	 }
	 else
	 {	
 
		//COMPTEUR POUR NUM_PHOTO
		$sql = "SELECT MAX( NUM_PHOTO ) AS maxphoto FROM photos;";
 
		$exec = mysql_query($sql, $connec) or die("erreur -> ".mysql_error());
 
		if($ligne = mysql_fetch_array($exec))
		{
			$num = $ligne['maxphoto'] + 1;
		}
 
		$repertoire = "rep_photos/";
		$fichier = basename($_FILES['fichier']['name']);
		$taille_maxi = 6000000;
		$taille = filesize($_FILES['fichier']['tmp_name']);
		$extensions = array('.png', '.gif', '.jpg', '.jpeg', '.PNG', '.GIF', '.JPG', '.JPEG');
		$extension = strrchr($_FILES['fichier']['name'], '.');
 
		//Début des vérifications de sécurité...
		if(!in_array($extension, $extensions)) //Si l'extension n'est pas dans le tableau
		{$erreur = 'Vous devez uploader un fichier de type png, gif, jpg, jpeg, txt ou doc...';}
		if($taille>$taille_maxi)
		{$erreur = 'Le fichier est trop gros...';}
 
		 //UPLOAD DE L'IMAGE
 
		 if(!isset($erreur)) //S'il n'y a pas d'erreur, on upload
		 {
			//On formate le nom du fichier ici...
			$fichier = strtr($fichier, 
					  'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 
					  'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
			$fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier);
 
			if(move_uploaded_file($_FILES['fichier']['tmp_name'], $repertoire . $fichier)) 
			{//Upload réussi - //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
			}
			else //Sinon la fonction renvoie FALSE).
			{$erreur ="Le chargement de l'image n'a pas fonctionnée";}
		 }
		 else
		 {echo $erreur;}
 
		 //REDIMENTIONNEMENT DE L'IMAGE
		 $x = 1280; 
		 $y = 1024; # Taille en pixel de l'image redimensionnée 
 
		 $size = getimagesize($repertoire.$fichier); 
 
		 if ( $size) 
		 { 		
			if ($size['mime']=='image/jpeg' )
			{ 
				$img_big = imagecreatefromjpeg($repertoire.$fichier); # On ouvre l'image d'origine 
				$img_new = imagecreate($x, $y); 
				# création de la miniature 
				$img_mini = imagecreatetruecolor($x, $y) 
				or   $img_mini = imagecreate($x, $y); 
 
				// copie de l'image, avec le redimensionnement. 
				imagecopyresized($img_mini,$img_big,0,0,0,0,$x,$y,$size[0],$size[1]); 
 
					imagejpeg($img_mini,$repertoire.$fichier ); 
			 }
		 }
 
		 //RECUPERATION DONNEES FORMULAIRES
		 $nom = strtoupper(mysql_real_escape_string($_POST['nom']));
		 $nom = strtr($nom,$accent,$noaccent); 
 
		 $entite = strtoupper(mysql_real_escape_string($_POST['entite']));
		 $entite = strtr($entite,$accent,$noaccent); 
 
		 $lieu = strtoupper(mysql_real_escape_string($_POST['lieu']));
		 $lieu = strtr($lieu,$accent,$noaccent); 
 
		 $commune = strtoupper(mysql_real_escape_string($_POST['commune']));
		 $commune = strtr($commune,$accent,$noaccent); 
 
		 $copyright = strtoupper(mysql_real_escape_string($_POST['copyright']));
		 $copyright = strtr($copyright,$accent,$noaccent); 
 
		 $mois = $_POST['mois'];
		 $jour = $_POST['jour'];
		 $annee = $_POST['annee'];
		 $d = mktime(0,0,0,$mois,$jour,$annee);
		 $dateprise = date("Y-m-d",$d); 
		 $chemin = $repertoire.$fichier;   
 
		 //INSERTION DANS LA TABLE photos
		 $query="INSERT INTO photos (NUM_PHOTO, ENTITE, NOM_PHOTO, LIEU_DIT, NUM_VILLE, DATE, COPYRIGHT, CHEMIN) "
		 ."VALUES (".$num.", '$entite', '$nom', '$lieu', '$commune', '$dateprise', '$copyright', '$chemin');";
 
		 $exec=mysql_query($query,$connec) or die("erreur -> ".mysql_error());
 
		 $tableautheme = $_POST['cbTheme'];
		 //print_r($_POST['cbTheme']); affiche les valeurs cochées du tableau généré
		 //INSERTION DANS LA TABLE photo_theme
		 foreach( $tableautheme as $idtheme ) 
		 {
			$id = $idtheme.$num;
 
			$query="INSERT INTO photo_theme (NUMERO, NUM_THEME, NUM_PHOTO) VALUES ($id, $idtheme, $num);";
 
			$exec=mysql_query($query,$connec) or die("erreur -> ".mysql_error());
		 }
 
		echo "<SCRIPT LANGUAGE='JavaScript'>";
		echo "alert('La photo a bien été ajoutée.')";
		echo "</SCRIPT LANGUAGUE>";
	}
}
 
if (isset($msg))
{
	echo "<p align='center'><img src='interface/attention.png' width='30' height='30' align='absmiddle'>&nbsp;&nbsp;$msg</p>";
 
}
 
?>
</head>
 
<body>
<table width="1000" border="0" cellpadding="10" cellspacing="0" align="center">
  <tr>
    <td background="interface/fond.png" class="Titre">Insertion d'une photo dans la base de données</td>
  </tr>
</table>
<table width="1000" border="0" cellpadding="10" cellspacing="0" align="center">
  <tr>
    <td class="cadre">
		<div align="center">
		<form enctype="multipart/form-data" action="insert.php" method="post" name="form1">
		   <div align="center">
		  <table width="600" border="0" cellspacing="5">
			   <tr>
				<td width="139" class="Pied">* champs obligatoires </td>
				<td width="442">&nbsp;</td>
			</tr>
			  <tr>
				<td><div align="right" class="Formulaire">Entit&eacute; * : </div></td>
				<td>            <div align="left">
				  <select name="entite" id="entite">
					<option value=''>Sélectionnez une entité</option>
					<option value='PAYS CHARENTE LIMOUSINE'>PAYS CHARENTE LIMOUSINE</option>
					<option value='CDC CONFOLENTAIS'>CDC CONFOLENTAIS</option>
					<option value='CDC HAUTE CHARENTE'>CDC HAUTE CHARENTE</option>
				  </select>        
				</div></td>
			</tr>
			  <tr>
				<td><div align="right" class="Formulaire">Nom de la photo  * : </div></td>
				<td>            <div align="left">
				  <input name="nom" type="text" id="nom" size="60">        
				</div></td>
			</tr>
			  <tr>
				<td><div align="right" class="Formulaire"> Lieu-dit  : </div></td>
				<td>            <div align="left">
				  <input name="lieu" type="text" id="lieu" size="60">        
				</div></td>
			</tr>
			  <tr>
				<td><div align="right" class="Formulaire">Ville * : </div></td>
				<td>            <div align="left">
				<select name="commune" id="commune">
			        <option>Sélectionnez la ville</option>
		            <?php 
						$sql = "SELECT `NUM_VILLE` , `NOM_VILLE` FROM `villes` ORDER BY `villes`.`NOM_VILLE` ASC ;";
 
						$exec = mysql_query($sql, $connec);
 
						while($ligne = mysql_fetch_array($exec))
						{
							$id = $ligne['NUM_VILLE'];
							$lib = $ligne['NOM_VILLE'];
							echo "<option value=$id>$lib</option>";
						}
					?>
                  </select>        
				</div></td>
			</tr>
			  <tr>
				<td><div align="right" class="Formulaire">Date de prise de vue : </div></td>
				<td>            <div align="left">
				  <select name="jour" id="jour">
                    <?php 
		    $i = 1;
			$t=getdate();
			$jour="$t[mday]"; 
			echo "<option value=$jour>$jour</option>";
			while ($i <= 31)
			{
				echo "<option value=$i>$i</option>";
				$i = $i + 1 ;
			}
		?>
                  </select>
                  <select name="mois" id="mois">
                    <?php 
		    $i = 1;
			$t=getdate();
			$mois="$t[mon]"; 
			echo "<option value=$mois>$mois</option>";
			while ($i <= 12)
			{
				echo "<option value=$i>$i</option>";
				$i = $i + 1 ;
			}
		?>
                  </select>
                  <select name="annee" id="annee">
                    <?php
						$t=getdate();
						$an="$t[year]"; 
						$i = 1997;
						$t=getdate();
						echo "<option value=$an>$an</option>";
						while ($i <= $an)
						{
							echo "<option value=$i>$i</option>";
							$i = $i + 1 ;
						}
					?>
                  </select>
				  </div></td>
			</tr>
			  <tr>
				<td><div align="right" class="Formulaire"> Copyright * : </div></td>
				<td>            <div align="left">
				  <input name="copyright" type="text" id="copyright" size="55">        
				</div></td>
			</tr>
			  <tr>
				<td><div align="right" class="Formulaire">S&eacute;lectionnez la photo  * :</div></td>
				<td>
				  <div align="left">
					<input type="hidden" name="MAX_FILE_SIZE" value="10000000">
                    <INPUT type="file" name="fichier" size="30" id="fichier">
                    <br>
                    (taille maxi 5Mo - formats support&eacute;s : jpg, jpeg, gif, png) </div></td>
			</tr>
			  <tr>
				<td><div align="right" class="Formulaire">Th&egrave;mes  * :</div></td>
				<td>
				  <div align="left">
					  <?php
						$sql = "SELECT NUM_THEME, NOM_THEME FROM themes ORDER BY NOM_THEME;";
 
						$query = mysql_query($sql,$connec) or die("erreur -> ".mysql_error());
 
						while ($ligne=mysql_fetch_array($query))
						{
							$lib = $ligne['NOM_THEME'];
							$id = $ligne['NUM_THEME'];
							echo "<input type='checkbox' name='cbTheme[]' value=$id>&nbsp;$lib</br>";
							//<input name=$id type='text' id=$id value=$id size='5' style='visibility:hidden'></br>";
						}
					  ?>
				  </div></td>
			  </tr>
			  <tr>
			    <td>&nbsp;</td>
			    <td>&nbsp;</td>
		      </tr>
			  <tr>
			    <td>&nbsp;</td>
			    <td><input name="insert" type="submit" id="insert" value="Envoyer" ></td>
		      </tr>
			 </table>
		   </div>
		   </form>
	  </div>
	</td>
  </tr>
</table>
</body>
</html>