Ver Mensaje Individual
  #6 (permalink)  
Antiguo 07/06/2012, 19:23
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: exportar consulta de base de datos a archivo txt abierto

hasta el momento llevo esta parte

Código HTML:
Ver original
  1. <p><a href="index.php?controller=correo_&accion=exportar_correos&file=datos.txt">Exportar</p></a>

Código PHP:
Ver original
  1. /*------------------  Funcion Menu Usuarios  ------------------*/
  2.    
  3.     function exportar_correos()
  4.     {
  5.            
  6.           require 'models/correo_Model.php';
  7.  
  8.               $ls = new Correo();
  9.               $fl = $ls -> list_allcorreos($db);   
  10.  
  11.              
  12.              
  13.        
  14.         require 'views/exportar.php';
  15.        
  16.     }


y en exportar.php

Código PHP:
Ver original
  1. <?php
  2.  
  3.  
  4.  
  5. if (!isset($_GET['file']) || empty($_GET['file'])) {
  6.     exit();
  7. }
  8.  
  9. $root = "views/";
  10. $file = basename($_GET['file']);
  11. $path = $root.$file;
  12. $type = '';
  13.  
  14. if (is_file($path)) {
  15.     $size = filesize($path);
  16.     if (function_exists('mime_content_type')) {
  17.         $type = mime_content_type($path);
  18.     } else if (function_exists('finfo_file')) {
  19.         $info = finfo_open(FILEINFO_MIME);
  20.         $type = finfo_file($info, $path);
  21.         finfo_close($info);  
  22.     }
  23.     if ($type == '') {
  24.         $type = "application/force-download";
  25.     }
  26.  
  27.     header("Content-Type: $type");
  28.     header("Content-Disposition: attachment; filename=\"$file\"");
  29.     header("Content-Transfer-Encoding: binary");
  30.     header("Content-Length: " . $size);
  31.  
  32.     readfile($path);
  33. } else {
  34.     die("File not exist !!");
  35. }
  36. ?>
  37.  
  38.  
  39. al darle click a exportar logro abrir el archivo txt pero solo en que parte tengo que incluir este codigo para imprimir en el txt
  40.  
  41. [HIGHLIGHT="PHP"]
  42. <?php
  43.   $ar=fopen("views/datos.txt","w+") or
  44.   die("Problemas en la creacion");
  45.  
  46.   fputs($ar,"\r\n");
  47. for ( $i = 1 ; $i <= 10 ; $i ++) {
  48. //print $i ;
  49. fputs($ar,"$i");
  50. fputs($ar,"\r\n");
  51. }
  52.   ?>

[/HIGHLIGHT]