Foros del Web » Programando para Internet » Javascript »

problema con agregar campos de fele

Estas en el tema de problema con agregar campos de fele en el foro de Javascript en Foros del Web. Hola Amigos. Tengo un problema con campos de type='file' cuando quiero obtener archivo en código de PHP, estoy haciendo de esta manera pero no me ...
  #1 (permalink)  
Antiguo 25/05/2011, 13:22
 
Fecha de Ingreso: marzo-2010
Ubicación: Buenos Aires
Mensajes: 25
Antigüedad: 14 años, 1 mes
Puntos: 2
problema con agregar campos de fele

Hola Amigos. Tengo un problema con campos de type='file' cuando quiero obtener archivo en código de PHP, estoy haciendo de esta manera pero no me funciona:

Código HTML:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ttt</title>
<script type="text/javascript">
<!--

function addEvent()
{
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById("theValue").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "File: <input type='file' id='myfile[] name='myfile[]'> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\')\">Remove</a>";
ni.appendChild(newdiv);
}

function removeEvent(divNum)
{
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
var numi = document.getElementById('theValue');
numi.value = numi.value - 1;
}


function validate ()
{
//alert ('hi');
//var ni = document.getElementById('myfile');
//alert(ni);
return true;
}

//-->
</script>
</head>

<body>
<form method='post' action='upload.php' enctype="multipart/form-data" name='form1' onsubmit='return validate()'>
<input type="hidden" value="0" id="theValue" name='theValue'/>
<p><a href="javascript:;" onclick="addEvent();">agregar campo para archivo</a></p>
<div id="myDiv"> <script type="text/javascript">addEvent(); </script></div>
<input type='submit' name='submit'>
</form>
</body>
</html> 
y archivo de upload.php

Código PHP:
<?php
    
echo $_FILES['myfile']['name'].' Prueba1<br>';
    echo 
$_REQUEST['myfile'].' Prueba2<br>';
    
print_r ($_FILES['myfile']['name'].' Prueba3<br>');
?>
y bo no funca no me pasa archivo ó no toma no se qué casa si alguien me puede ayudar lo agradezco mucho.

Etiquetas: campos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:51.