Précédent   Forum des professionnels en informatique > PHP > Langage > Fichiers
Fichiers Forum d'entraide sur les fichiers avec PHP. Avant de poster -> FAQ fichiers et Sources fichiers
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 03/12/2006, 17h37   #1
Invité régulier
 
Inscription : décembre 2006
Messages : 39
Détails du profil
Informations forums :
Inscription : décembre 2006
Messages : 39
Points : 9
Points : 9
Par défaut [Upload] Récuperation de valeur de tableau pour multiupload

Tout d'abord, bonsoir tout le monde,

Voilà ca fait 2 jours que je m arrache les yeux sur un script multi upload d'images.

Je dois insérer dans la base de donnée le nom de l'image+extension, dans chaques champs de la table (img1, img2, img3,img4,...)

le probleme c'est que au lieu de m enregisrter les valeurs ainsi img1=chalet1.jpg , img2=chalet2.jpg, img3=chalet3.jpg cela me l enregistre ainsi : img1=C img2=h, img3=a, img4=l,... (chalet..)
J ai un soucis avec ma boucle foreach on dirait, mais pourtant elle marche très bien pour l upload de l image sur le serveur (le nom+extension est ok)

Voici le fichier complet. d avance merci a celui qui peut m aider

Code :
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
<?
include('verifylogin.php');
require_once('connect_sql.php'); 
include ("header.html");
 
//script upload
if (isset($_FILES['fichier']))
{
//$_FILES existe
foreach ($_FILES['fichier']['name'] as $key => $value) {
$fichier=$value;//nom reel de l'image
$size=$_FILES['fichier']['size'][$key]; //poids de l'image en octets
$tmp=$_FILES['fichier']['tmp_name'][$key];//nom temporaire de l'image (sur le serveur)
$type=$_FILES['fichier']['type'][$key];//type de l'image
//On récupère la taille de l'image
list($width,$height)=getimagesize($tmp);
if (is_uploaded_file($tmp)) //permet de vérifier si le fichier a été uplodé via http
{
//vérification du type de l'img, son poids et sa taille
if ($type="image/jpg" && $size<=120500 && $width<=320 && $height<=170 )
{
// type mime gif, poids < à 20500 octets soit environ 20Ko, largeur = hauteur = 100px
//Pour supprimer les espaces dans les noms de fichiers car celà entraîne une erreur lorsque vous voulez l'afficher
$fichier = preg_replace ("` `i","",$fichier);//ligne facultative :)
//On vérifie s'il existe une image qui a le même nom dans le répertoire
if (file_exists('../photos/'.$fichier))
{
//Le fichier existe on rajoute dans son nom le timestamp du moment pour le différencier de la première (comme cela on est sûr de ne pas avoir 2 images avec le même nom :) )
$nom_final= preg_replace("`.jpg`is",date("U").".jpg",$fichier);
}
else {
$nom_final= preg_replace("`.jpg`is",date("U").".jpg",$fichier); //l'image n'existe pas on garde le même nom
}
//on déplace l'image dans le répertoire final
if (move_uploaded_file($tmp,'../photos/'.$nom_final)) {
//Message indiquant que tout s'est bien passé
//Pour le test on affiche l'image
echo '';
}
else {
//l'image ne peut être déplacée, on supprime le fichier temporaire
@ unlink ($tmp);
echo '<center><font color=black>L\'image n\'a pu être déplacée !</font></center>';
}
 
}
else {
//Le type mime, ou la taille ou le poids est incorrect
echo '<center><font color=black>Votre image a été rejetée (poids, taille ou type incorrect)</font></center>';
}
}
}
}
 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$id= "".$_GET['id']."";
 
//$nom_final[$i] = $fichier;
 
$fichier =  $_POST["nom_final"][0];
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE vitrine SET location=%s, nom=%s, pieces=%s, img1='".$nom_final['1']."', img2='".$nom_final['2']."', img3='".$nom_final['3']."', img4='".$nom_final['4']."', img5='".$nom_final['5']."', img6='".$nom_final['6']."', img7='".$nom_final['7']."', img8='".$nom_final['8']."' WHERE id='$id'",
                       GetSQLValueString($_POST['textarea'], "text"),
					   GetSQLValueString($_POST['textfield'], "text"),
					   GetSQLValueString($_POST['pieces'], "text"),
                       GetSQLValueString($_FILES['fichier'], "text"));
 
  mysql_select_db($database, $sql_connect);
  $Result1 = mysql_query($updateSQL, $sql_connect) or die(mysql_error());
}
 
mysql_select_db($database, $sql_connect);
$query_edito_modif = "SELECT * FROM vitrine where id='$id'";
$query_edito_modif = mysql_query($query_edito_modif, $sql_connect) or die(mysql_error());
$row_query_edito_modif = mysql_fetch_assoc($query_edito_modif);
$totalRows_query_edito_modif = mysql_num_rows($query_edito_modif);
 
?>
<div align="center">
<table width="950" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="192" rowspan="3" valign="top"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="192" height="381">
  <param name="movie" value="../swf/savalogis_bas.swf" />
  <param name="quality" value="high" />
  <embed src="../swf/savalogis_bas.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="192" height="381"></embed>
</object></td>
<td width="112" valign="top" class="td_h_menu"></td>
<td width="358" align="left" valign="middle" class="td_home_txt">Editer la vitrine</td>
<td width="286" valign="middle" class="td_home_txt"><div align="right"></div></td>
</tr>
<tr>
<td valign="top">
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
  <td width="112" height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top" class="td_home_txt"><div align="left"><a href="admin.php?lng=fr">Administration</a></div></td>
  </tr>
  <tr>
    <td height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top" class="td_menu"><div align="left"><a href="affich_vitrine.php?lng=fr">Modifs vitrines</a></div></td>
  </tr>
  <tr>
    <td height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top" class="td_home_txt"><div align="left"><a href="affich_vente.php?lng=fr">Modifs ventes</a></div></td>
  </tr>
  <tr>
    <td height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top" class="td_home_txt"><div align="left"><a href="add_vitrine.php?lng=fr">Ajout vitrine</a></div></td>
  </tr>
  <tr>
    <td height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top" class="td_home_txt"><div align="left"><a href="add_vente.php?lng=fr">Ajout Vente</a></div></td>
  </tr>
  <tr>
    <td height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top" class="td_home_txt"><div align="left"><a href="../index.php?lng=fr">Site</a></div></td>
  </tr>
  <tr>
    <td height="10" valign="top"></td>
  </tr>
  <tr>
    <td height="10" valign="top" class="td_home_txt"><div align="left"><a href="../logout.php?lng=fr">D&eacute;connexion</a></div></td>
  </tr>
  </table></td>
<td rowspan="2">
  <!-- 
Script. Insertion du plugin Tiny_mce, qui permet d'afficher un &eacute;diteur de texte modifiable
-->
  <script language="JavaScript" type="text/javascript" src="../modules/tiny_mce/tiny_mce.js"></script>
  <script language="JavaScript" type="text/javascript">
tinyMCE.init({
	theme : "simple",
	mode : "textareas"
 
});
  </script>
  <!-- fin du script -->
 
  <div align="left"  style="padding-left: 25px;">
  <form action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="post" name="form1" id="form1">
    Nom : <br />
  <input name="textfield" type="text" class="input" value="<?php echo $row_query_edito_modif['nom']; ?>" size="35" maxlength="50" />
  <br />
  <br />
    Location : <br />
  <textarea name="textarea"  class="input" cols="27" rows="2"><?php echo $row_query_edito_modif['location']; ?></textarea>
  <br />
    Nbre de pi&egrave;ces :
  <input name="pieces" type="text" class="input" value="<?php echo $row_query_edito_modif['pieces']; ?>" size="6" />
 
  <span class="small_texte"><font color="red"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br />
    <br />
    La photo 1 est l'image principale</font></span>
 <? 
 
	if(file_exists("../photos/".$filename.".jpg")){
		echo "<br /><b>Photo 1 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 2 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 3 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 4 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 5 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 6 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 7 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 8 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
	}
	elseif(file_exists("../photos/".$filename.".gif")){
		echo "<br /><b>Photo 1 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 2 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 3 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 4 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 5 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 6 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 7 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 8 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
 
	}
	else{
			echo "<br /><b>Photo 1 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 2 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 3 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 4 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 5 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 6 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 7 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
		echo "<br /><b>Photo 8 :</b>&nbsp;&nbsp;";
		echo "<input type=\"file\" name=\"fichier[]\" accept=\"image/jpg\" size=\"20\" maxlength=\"50\">";
 
	}
?>
  <br />
  <input type="submit" name="form1" value="Valider" />
  <input type="hidden" name="MM_update" value="form1" />
  </form>
</div>
<td rowspan="2" valign="bottom"><br />
<table width="62%" border="1" align="center" cellpadding="5">
<tr>
<td width="41%">Photo1 <img src="../photos/<?php echo $row_query_edito_modif['img1']; ?>" width="90" height="75" /></td>
<td width="59%">Photo 2 <img src="../photos/<?php echo $row_query_edito_modif['img2']; ?>" width="90" height="75" /></td>
</tr>
<tr>
<td>Photo 3 <img src="../photos/<?php echo $row_query_edito_modif['img3']; ?>" width="90" height="75" /></td>
<td>Photo 4 <img src="../photos/<?php echo $row_query_edito_modif['img4']; ?>" width="90" height="75" /></td>
</tr>
<tr>
<td>Photo 5 <img src="../photos/<?php echo $row_query_edito_modif['img5']; ?>" width="90" height="75" /></td>
<td>Photo 6 <img src="../photos/<?php echo $row_query_edito_modif['img6']; ?>" width="90" height="75" /></td>
</tr>
<tr>
<td>Photo 7 <img src="../photos/<?php echo $row_query_edito_modif['img7']; ?>" width="90" height="75" /></td>
<td>Photo 8 <img src="../photos/<?php echo $row_query_edito_modif['img8']; ?>" width="90" height="75" /></td>
</tr></table>
<br /><br />
</tr></table>
</td>
<?
include ("../footer.html");
?>
Skippy1 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/12/2006, 23h24   #2
Modérateur
 
Avatar de mathieu
 
Inscription : juin 2003
Messages : 4 893
Détails du profil
Informations forums :
Inscription : juin 2003
Messages : 4 893
Points : 4 466
Points : 4 466
en effet tu parcours mal le tableau
utilise le code suivant pour voir le contenu de $_FILES et tu verras comment faire ta boucle
Code :
1
2
3
echo '<pre>';
print_r($_FILES);
echo '</pre>';
__________________
Modérateur PHP
mathieu est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/12/2006, 23h31   #3
Invité régulier
 
Inscription : décembre 2006
Messages : 39
Détails du profil
Informations forums :
Inscription : décembre 2006
Messages : 39
Points : 9
Points : 9
Hello, merci pour ta réponse.

Mais bon je pense que j'ai tout faux ainsi (aux dire d'un ami)
En fait il parait que je ne peut pas récuperer le nom et l extension ainsi dans ma base, car je stocke les images dans la meme table que le reste (texte, infos, par exemple). Il m a parlé de créér une table pour les images avec une ID non incrementée et de voir du coté de mysql_insert_id.

Je n ai malheureusement pas compris grand chose

Mais je vais tester ton débug pour voir ce que ca me donne

bonne soirée
Skippy1 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/01/2007, 07h19   #4
Expert Confirmé
 
Avatar de Sub0
 
Homme
Inscription : décembre 2002
Messages : 3 468
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 39

Informations forums :
Inscription : décembre 2002
Messages : 3 468
Points : 3 115
Points : 3 115
Envoyer un message via MSN à Sub0 Envoyer un message via Skype™ à Sub0
Pour info, j'ai réalisé un script d'upload PHP avec un formulaire Flash permettant de sélectionner plusieurs fichiers en une seule fois, d'afficher une progressbar, et d'envoyer des gros fichiers via un script CGI :
http://developpez.net/forums/showthread.php?t=231635#8

N'oublis pas le tag résolu ( en bas de cette page)
Sub0 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 19h00.


 
 
 
 
Partenaires

Hébergement Web