Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/04/2010, 13:26
diego007007
 
Fecha de Ingreso: enero-2009
Ubicación: en la casa
Mensajes: 223
Antigüedad: 15 años, 3 meses
Puntos: 3
Agregar input type="file" dinamicamente

Hola Amig@s, hace mucho tiempo que ya no programo en JavaScript y resulta que deceo hacer que dinamicamente aparescan input type="file" para ingresar fotos en un formulario, el problema esta que en el campo name de los campos input, no consigo que cambien los nombres, les dejo mi codigo para ver si alguien me puede ayudar, de antemano muchas gracias.
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<script> 
function agregaFila( id ) { 
    var tabla = document.getElementById( id ); 
    var tbody = document.getElementById( tabla.id ).tBodies[0]; 
    var row = tbody.rows[0] .cloneNode( true ); 
    var id = 1; 
    while( document.getElementById( tabla.id+'_fila_'+id ) ) { 
        id++; 
    } 
    if (id<=3){ 
    row.id = tabla.id+'_fila_'+id; 
    row.style.display = ''; 
    tbody.appendChild( row ); 
    } 


function borraFila( fila ) { 
var id = fila.id; 
if( fila.parentNode.rows.length <= 2 ) return; 
document.getElementById( id ).parentNode.removeChild( document.getElementById(id) ); 

</script>
</head>
<body>  
<form enctype="multipart/form-data" action="subir.php" method="POST"> 
    <select size="1" name="admin[]"> 
    <option value="Male">Masculino</option>
    <option value="Feme">Femenino</option>
    </select><br>
    <table id="tabla_1" >  
        <tbody> 
            </tr> 
            <tr> 
                <td><input type="file" name="pix1" size="60"> </td> 
                <td><a href="#" onClick="borraFila(this.parentNode.parentNode)">Eliminar</a></td> 
            </tr> 
            <tr id="tabla_1_fila_1" > 
                <td><input type="file" name="pix1" size="60"> </td> 
                <td> </td> 
            </tr> 
        </tbody> 
            <tr> 
                <td ><a href="javascript:agregaFila( 'tabla_1' );">Agregar Fila</a></td>  
            </tr> 
        </table> 
    <p><input type="submit" name="Upload" value="Aceptar">  
</form>  
</body>
</html>  
<?php
include "coneccion.php";

$admin = @$_POST["admin"];
for (
$i=0;$i<count($admin);$i++){ 
    
$admi $admin[$i]; 
}
if(isset(
$_POST['Upload'])){    
     
$nombre1 $_FILES['pix1']['name'];
    
$nombre2 $_FILES['pix2']['name'];
    
$nombre3 $_FILES['pix3']['name'];
    
$img1="./imagenes/".$nombre1.$_FILES['pix']['name'];  
    
$img1_tmp $_FILES["pix"]["tmp_name"];  
    
move_uploaded_file($img1_tmp,$img1);
    
$img2="./imagenes/".$nombre2.$_FILES['pix']['name'];  
    
$img2_tmp $_FILES["pix"]["tmp_name"];  
    
move_uploaded_file($img2_tmp,$img2);
    
$img3="./imagenes/".$nombre3.$_FILES['pix']['name'];  
    
$img3_tmp $_FILES["pix"]["tmp_name"];  
    
move_uploaded_file($img3_tmp,$img3);
    
//echo "<p><b>El archivo se ha cargado satisfactoriamente:</b>{$_FILES['pix']['name']}({$_FILES['pix']['size']})</p>";  
    
$query "INSERT INTO articulos (fecha_upl, original_upl, id_admin) VALUES ( NOW(), '".$nombre1."' , '".$nombre2."', '".$nombre3."', '".$admi."')";
    
mysql_query($query);
}
?>
salu2