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.