<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hay líneas comentadas con "//", aclaro PORQUE me olvidé de sacarlas y no hay que tenerlas en cuenta.</span><br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">El 5 de noviembre de 2013 17:35, Maximiliano Lizondo <span dir="ltr"><<a href="mailto:lizondomaximiliano@gmail.com" target="_blank">lizondomaximiliano@gmail.com</a>></span> escribió:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hay líneas comentadas con "//", aclaro por que me olvidé de sacarlas y no hay que tenerlas en cuenta.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">El 5 de noviembre de 2013 17:30, Maximiliano Lizondo <span dir="ltr"><<a href="mailto:lizondomaximiliano@gmail.com" target="_blank">lizondomaximiliano@gmail.com</a>></span> escribió:<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hola, tengo una duda con respecto a un ejercicio sobre subir archivos y listarlos. El enunciado era el siguiente:<div>
<br></div><div><span style="font-size:11pt;line-height:115%;font-family:Calibri,sans-serif">"Realice
un script que permita subir archivos a un directorio y luego los muestre
listados en una página con un link para su descarga."</span></div><div><font face="Calibri, sans-serif"><span style="font-size:15px;line-height:17px"><br></span></font></div><div><font face="Calibri, sans-serif"><span style="font-size:15px;line-height:17px">Pego el código para facilitar la explicación de mi duda:</span></font></div>
<div><font face="Calibri, sans-serif"><span style="font-size:15px;line-height:17px"><br></span></font></div><div><font face="Calibri, sans-serif"><div><span style="font-size:15px;line-height:17px"><b><?php</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>$directorio="subidas/";</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>if (ISSET($_POST['btn_enviar']))</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>{</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>$archivo=$_FILES['userfile']['name'];</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>if (is_uploaded_file($_FILES['userfile']['tmp_name']))</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>{</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>$path=$directorio.$archivo;</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>//$path=$directorio.$_FILES['userfile']['name'];</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>//$archivo=$_FILES['userfile']['name'];</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>$msg="El archivo {$archivo} fue cargado satisfactoriamente";</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>//print('<br><br>El archivo '.'<b>'.$archivo.'</b>'.' fue cargado satisfactoriamente.');</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>move_uploaded_file($_FILES['userfile']['tmp_name'],$path);</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>}</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>else</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>{</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>$msg="Posible ataque durante la subida de archivos. Nombre de archivo: {$archivo}";</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>//print('Posible ataque durante la subida de archivos. Nombre de archivo: '.$archivo);<span style="white-space:pre-wrap"> </span></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>}</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>}</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>if(isset($_POST['Borrar']))</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>{</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>unlink($directorio.$_POST['a']);</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>$msg = "Archivo borrado: {$_POST['a']}";</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>}</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>$contenido=scandir($directorio);</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>array_shift($contenido);</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>array_shift($contenido);</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b>?></b></span></div><div><span style="font-size:15px;line-height:17px"><b><br></b></span></div><div><span style="font-size:15px;line-height:17px"><b><!DOCTYPE html></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><br></b></span></div><div><span style="font-size:15px;line-height:17px"><b><html></b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><head></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><title> GUIA 3 - Ejercicio 1</title></b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span></head></b></span></div>
<div><span style="white-space:pre-wrap;font-size:15px;line-height:17px"><b> </b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><body></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><div><h1>Ejercicio sobre UPLOAD</h1></div></b></span></div><div><span style="white-space:pre-wrap;font-size:15px;line-height:17px"><b> </b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><form enctype="multipart/form-data" action="avanz_3_1.php" method="post"></b></span></div>
<div><span style="white-space:pre-wrap;font-size:15px;line-height:17px"><b> </b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><fieldset></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><input type="hidden" name="MAX_FILE_SIZE" value="100000"/></b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>Enviar este archivo:<input name="userfile" type="file"/></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><input type="submit" name="btn_enviar" value="Subir archivo"/></b></span></div><div>
<span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span></fieldset><span style="white-space:pre-wrap"> </span></b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span></form></b></span></div>
<div><span style="white-space:pre-wrap;font-size:15px;line-height:17px"><b> </b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><hr></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><br></b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><ul></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><?php</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>foreach ($contenido as $nombre_archivo)</b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>{</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>?><span style="white-space:pre-wrap"> </span></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><li></b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>Archivo: <a href="<?=$directorio?><?=$nombre_archivo?>"><?=$nombre_archivo?></a></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><form id="b" name="b" method="post"></b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><input name="a" id="a" type="hidden" value="<?=$nombre_archivo?>" /></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><input type="submit" name="Borrar" value="Borrar" /></b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span></form></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span></li> </b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span><?php<span style="white-space:pre-wrap"> </span></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>}</b></span></div><div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span>?><span style="white-space:pre-wrap"> </span></b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span></ul></b></span></div><div><span style="white-space:pre-wrap;font-size:15px;line-height:17px"><b> </b></span></div>
<div><span style="font-size:15px;line-height:17px"><b><span style="white-space:pre-wrap"> </span></body></b></span></div><div><span style="font-size:15px;line-height:17px"><b></html></b></span></div><div style="font-size:15px;line-height:17px">
<br></div><div style="font-size:15px;line-height:17px">La duda es la siguiente: por cada archivo subido se genera un link y un formulario con un botón <b>"Borrar" </b>para borrar dicho archivo y un "input" de tipo "hidden" (<b>name="a"</b>) que contiene el nombre de dicho archivo. Pero noté que todos los formularios e inputs que se generan, tienen los mismos nombres para cada archivo subido. El tema es que cuando se hace click en algún botón<b> "Borrar"</b>, se borra el archivo correspondiente a dicho botón. ¿Cómo hace el intérprete PHP para saber a qué input <b>"a"</b> me estoy refiriendo, cuando le paso el parámetro la variable <b>$_POST['a']</b>? se entiende la duda?</div>
<span><font color="#888888">
</font></span></font><span><font color="#888888"><div><br></div>-- <br><div dir="ltr"><div><b><font face="trebuchet ms, sans-serif">Ing. Maximiliano Andrés Lizondo</font></b></div><ul><li style="text-align:left">
<font><i>Teléfonos: </i><font face="tahoma, sans-serif"><b>0223-493-5488</b> (particular) - <b>2236-321708</b> (móvil)</font><br>
</font></li><li style="font-style:italic;text-align:left"><font><i>Perfil profesional en <b>LinkedIn</b>: </i><a href="http://ar.linkedin.com/pub/maximiliano-andr%C3%A9s-lizondo/61/906/344" style="font-style:normal;color:rgb(17,85,204)" target="_blank">http://ar.linkedin.com/pub/maximiliano-andr%C3%A9s-lizondo/61/906/344</a></font><br>
</li></ul></div>
</font></span></div></div>
</blockquote></div></div></div><div><div class="h5"><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div><b><font face="trebuchet ms, sans-serif">Ing. Maximiliano Andrés Lizondo</font></b></div><ul><li style="text-align:left">
<font><i>Teléfonos: </i><font face="tahoma, sans-serif"><b>0223-493-5488</b> (particular) - <b>2236-321708</b> (móvil)</font><br>
</font></li><li style="font-style:italic;text-align:left"><font><i>Perfil profesional en <b>LinkedIn</b>: </i><a href="http://ar.linkedin.com/pub/maximiliano-andr%C3%A9s-lizondo/61/906/344" style="font-style:normal;color:rgb(17,85,204)" target="_blank">http://ar.linkedin.com/pub/maximiliano-andr%C3%A9s-lizondo/61/906/344</a></font><br>
</li></ul></div>
</div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div><b><font face="trebuchet ms, sans-serif">Ing. Maximiliano Andrés Lizondo</font></b></div><ul><li style="text-align:left"><font><i>Teléfonos: </i><font face="tahoma, sans-serif"><b>0223-493-5488</b> (particular) - <b>2236-321708</b> (móvil)</font><br>
</font></li><li style="font-style:italic;text-align:left"><font><i>Perfil profesional en <b>LinkedIn</b>: </i><a href="http://ar.linkedin.com/pub/maximiliano-andr%C3%A9s-lizondo/61/906/344" style="font-style:normal;color:rgb(17,85,204)" target="_blank">http://ar.linkedin.com/pub/maximiliano-andr%C3%A9s-lizondo/61/906/344</a></font><br>
</li></ul></div>
</div>