
Subir n numero de fotos a un servidor mediante un ciclo en php
Publicado por Elesbaán Campos (2 intervenciones) el 01/03/2018 00:16:23
Saludos compañeros, quiero pedir su ayuda, tengo un formulario donde se especifica una carpeta y el numero de fotos que va a subir, a través de un archivo php generé un ciclo que recibe los archivos y se ejecuta las veces que sean necesarias para cada foto. espero explicarme. El problema es que pareciera realizar el proceso pero no sube ninguna imagen. Espero me puedan ayudar a encontrar mi error.
<= formulario =>
<= formulario=>
<= envio php=>
<= envio php=>
<= formulario =>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<form id='formulario2' method='post' enctype='multipart/form-data' action='assets/php/subirfotos.php'>
<input style="display:none;" type="text" id='producto2' name='producto2' value='<?php echo $seleccionada ?>' />
<input style="display:none;" type="text" id='numfotos3' name='numfotos3' value='<?php echo $numfotos ?>' />
<?php
$cont = 0;
$cont2= $cont + 1;
while ($cont < $numfotos ){
echo '<div style="width:33%; text-align: center; float: left;" ><h1 style="font-size: 1.2rem;">Foto '.$cont2.'</h1> <img style="width:50%; dragable=true;" src="../../img/'.$carpeta.'/'.$cont2.'.png" onerror="imgError(this);"> <br> ';
echo '<input style="margin-right: 2%; display: none; " type="text" name="nombre'.$cont2.'" id="nombre'.$cont2.'" value="'.$cont2.'.png" />';
echo'<input type="file" name="arachivo'.$cont2.'" id="archivo'.$cont2.'" class="inputfile inputfile-1"/>
<label for="archivo'.$cont2.'">
<svg xmlns="http://www.w3.org/2000/svg" class="iborrainputfile" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"></path></svg>
<span class="iborrainputfile">Seleccionar archivo</span>
</label></div>';
$cont = $cont + 1; $cont2= $cont + 1;
}
?>
</form>
<= formulario=>
<= envio php=>
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
<?php
require ('../../conexion.php');
$query = "SELECT Producto FROM `Productos` ORDER BY Producto ASC";
$resultado=$mysqli->query($query);
$query2 = "SELECT Fotos FROM Productos WHERE Producto = '$Producto'";
$resultado2 = $mysqli->query($query2);
$numfotos = $_POST['numfotos3'];
$producto = $_POST['producto2'];
$carpeta = '../../../img/'.$producto.'/';
$cont = 0;
$cont2= $cont + 1;
while ($cont < $numfotos ){
${"nombre" . $cont2} = $_POST['nombre'.$cont2];
${"nombre_archivo" . $cont2} = $_FILES['archivo'.$cont2]['name'];
${"tipo_archivo" . $cont2} = $_FILES['archivo'.$cont2]['type'];
${"tamaño_archivo" . $cont2} = $_FILES['archivo'.$cont2]['size'];
if (!file_exists($carpeta)) {
mkdir($carpeta, 0777, true);
}
$target_path = $carpeta;
$target_path = $target_path . basename($cont2.'.png');
if ($_FILES['archivo']["error"] > 0)
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Error, la imagen $cont2 no se subio correctamente al servidor')
</SCRIPT>");
}
else
{
move_uploaded_file($_FILES['archivo']['tmp_name'], $target_path);
$mensaje = "$cont2, ";
}
$cont2 = $cont2 + 1;
}
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Las imagenes $mensaje se han subido correctamente al servidor')
window.location.href='../../Productos.php'
</SCRIPT>");
// Cerrar la conexión
mysql_close($link);
exit;
?>
<= envio php=>
Valora esta pregunta


0