Bonjour,

J'ai complété et adapté un script d' upload, pour avoir la possibilité de choisir le nombre de formulaires pour la saisie. Jusqu'à là, ça marche.
J'ai récupéré un de mes scripts d'upload, je l'ai appliqué dessus, en faisant attention aux variables, mais là, ça ne marche plus.
Si vous voyez ce qui ne marche pas et pouvez me le dire, je vous en suis reconnaissant d'avance.

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
<?php
 
$user_ref = 11111;
 
/* variables à modifier */
$taillemax = 1024000; // taille max d'un fichier (multiple de 1024)
$filetype = "(jpeg|gif|png)"; // types de fichiers acceptés, séparés par |
$nametype = "(.jpeg|.jpg|.gif)"; // extensions correspondantes
$rep = "img/showroom/"; // répertoire de destination
$maxfichier = 5; // nombre maximal de fichiers
/* fin des modifications */
 
// fichier courant (URI absolue) : formulaire récursif
$PHP_SELF = basename($_SERVER['PHP_SELF']);
 
 
if(isset($_POST['Envoyer']))
 
{
//-----------------------Images----------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////
 
 
 
while(list($key,$value) = each($_FILES[photo][name]))
{
if(!empty($value))
 
		{   // this will check if any blank field is entered
$filename = $value;    // filename stores the value
 
 
$filename=str_replace(" ","_",$filename);
 
$add = "img/showroom/";   // upload directory path is set
//echo $_FILES[images][type][$key];     // uncomment this line if you want to display the file type
$data[] = "img/showroom/$filename";
 
copy($_FILES[photo][tmp_name][$key], $add);
chmod("$add",0777); // set permission to the file.
$img1 = $data[0];
$img2 = $data[1];
$img3 = $data[2];
$img4 = $data[3];
$img5 = $data[4];
 
		}
}
 
$query = "INSERT INTO repository_images(
id,
ref_entrepr,
image1,
image2,
image3,
image4,
image5
)
VALUES(
'',
'$user_ref',
'$img1',
'$img2',
'$img3',
'$img4',
'$img5'
)";
 
$result = mysql_query($query);
 
	if(!$result)
	{
	$feedback ='ERROR mysql';
	return $feedback;
	}
	else
	{
	echo"<span class=\"adok\">"."Insertion fichier OK"."</span>";
	echo"<br /><br /><br /><br />";
	}
 
}
 
?>
 
<label><?php echo TXT_PHOTOS; ?></label>
 
<?php
 
// 1 fichier par défaut (ou supérieur à $maxfichier)
$upload = (isset($_REQUEST['upload']) && $_REQUEST['upload'] <= $maxfichier) ? $_REQUEST['upload'] : 1;
 
// choix du nombre $upload de fichier(s)
echo "<form action='$PHP_SELF' method='post'>\n";
echo "Quantité <select name='upload' onChange=\"window.open(this.options[this.selectedIndex].value,'_self')\">\n";
for($i=1; $i<=$maxfichier; $i++) {
	echo "<option value='$PHP_SELF?upload=$i'";
	if($i == $upload) echo " selected";
	echo ">$i\n";
}
echo "</select>\n";
 
echo "<input type='submit' value='Modifier'></form>\n";
 
// le formulaire
echo "<form action='$PHP_SELF' enctype='multipart/form-data' method='post'>\n";
// boucle selon nombre de fichiers $upload
for($i=1; $i<=$upload; $i++) {
	echo "<input type='hidden' name='MAX_FILE_SIZE' value='$taillemax'>";
	echo "Fichier <input type='file' name='photo[]'></p>\n";
}
?>
<input type='submit' value='Envoyer'>
</form>