Hola !!!
Quería hacer un formulario con un campo " Subir fotos " que fuera variable, es decir, que pulsando un botón se fueran agregando campos del tipo " File ".
El caso es que el formulario funciona bien y agrega los campos correctamente, sin embargo los archivos no se " Suben " bien.
Os dejo el código, si me pudieran echar una mano os estaría muy agradecido.
Un saludo. ^_^
Código PHP:
<style type='text/css'>
div#fotos input
{
display: block;
margin-bottom: .5em;
}
</style>
<script type='text/javascript'>
/*
Máximo número de fotos
*/
MAX_FOTOS = 5;
/*
Número total de fotos
*/
totalFotos = 0;
function docLoad()
{
/*
Guardamos una referencia a la lista de fotos
*/
oDivFotos = document.getElementById("fotos");
}
function agregarFoto()
{
/*
Si el número de campos supera el máximo no continuamos
*/
if(totalFotos >= MAX_FOTOS){
alert('Superaste el número máximo de fotos');
return false;
}
/*
Creamos un objeto input para una nueva foto
*/
var oInput = document.createElement('input');
/*
Asignamos propiedades
*/
oInput.type = 'file';
oInput.name = 'fotos[]';
/*
Insertamos el objeto input en la lista de fotos
*/
oDivFotos.appendChild(oInput);
totalFotos++;
/*
Ponemos el foco del teclado en el cuadro de texto insertado
*/
oInput.focus();
}
</script>
<body onload='docLoad()'>
/*
Este es el input del formulario
*/
<div id='fotos'>
<p style="margin-bottom: 1px">
<input type='file' name='fotos[]'>
</div>
<input type='button' value='Agregar' onclick='agregarFoto()'>
<p>
/*
Y este el tratamiento que hago del formulario
*/
$uploaddir = "Fotos\Cine\ $pelicula";
if(is_uploaded_file($_FILES['fotos[0]']['tmp_name']))
{
move_uploaded_file($_FILES['fotos[0]']['tmp_name'],$uploaddir.'/'.$_FILES['fotos[0]']['name']);
}
if(is_uploaded_file($_FILES['fotos[1]']['tmp_name']))
{
move_uploaded_file($_FILES['fotos[1]']['tmp_name'],$uploaddir.'/'.$_FILES['fotos[1]']['name']);
}