Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/05/2011, 09:44
clavena
 
Fecha de Ingreso: septiembre-2010
Ubicación: Santiago, Chile
Mensajes: 47
Antigüedad: 13 años, 7 meses
Puntos: 0
Cargar archivo CSV en Tablas

Hola

Quisiera saber como volcar los datos de un archivo CSV en tablas html, tengo un codigo pero que me tira los datos hacia abajo y no me crea la tabla. Ah, y aparte no me mueve el archivo subido a la carpeta de destino. Saludos

Código HTML:
Ver original
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  3. <title>Documento sin título</title>
  4. </head>
  5.  
  6. <p>&nbsp;</p>
  7. <p>&nbsp;</p>
  8. <p>Test de Archivo</p>
  9. <form action="subir.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  10.   <p>
  11.     <label>
  12.       <input type="file" name="archivo" id="csv" />
  13.     </label>
  14.   </p>
  15.   <p>
  16.     <label>
  17.       <input type="submit" name="enviar" id="enviar" value="Subir Archivo" />
  18.     </label>
  19.   </p>
  20. </form>
  21. </body>
  22. </html>

Código PHP:
Ver original
  1. <?php require_once('Connections/connBD.php'); ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Documento sin título</title>
  7. </head>
  8.  
  9. <body>
  10. <?php
  11.  
  12. echo "Nombre Temporal: ".$_FILES['archivo']['tmp_name'].'<br>';
  13. echo "Tamaño del Archivo: ".$_FILES['archivo']['size'].'<br>';
  14. echo "Tipo de Archivo: ".$_FILES['archivo']['type'].'<br>';
  15. echo "Nombre del Archivo: ".$_FILES['archivo']['name'].'<br>';
  16. echo "<br>";
  17. /*
  18. $destino = "\Excel".$_FILES['archivo']['name'];
  19. $origen = $_FILES['archivo']['tmp_name'];
  20. if(move_uploaded_file($origen,$destino) == true)
  21.     echo 'Subido con Éxito'.'<br>';
  22. else
  23.     echo 'WTF!!!!';
  24. */
  25.  
  26. $fp = fopen ( $_FILES['archivo']['tmp_name'] , "r" );
  27. echo '<table width="700">';
  28. while (( $data = fgetcsv ( $fp , 2048, ";")) !== false ) // Mientras hay líneas que leer...
  29.     {
  30.         $i = 0;
  31.         foreach($data as $row)
  32.         {
  33.             echo '<tr>';   
  34.                 echo '<td>'.$row.'</td>';        // Muestra todos los campos de la fila actual
  35.             echo '</tr>';
  36.             $i++ ;
  37.         }
  38.     }
  39. echo '</table>';
  40. fclose($fp);
  41. ?>
  42. </body>
  43. </html>