Ver Mensaje Individual
  #3 (permalink)  
Antiguo 19/07/2009, 07:51
Avatar de gjx2
gjx2
 
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 9 meses
Puntos: 139
Respuesta: GENERAR txt y mostrarlo en el navegador

Es bien facil.

Imaginemos que tienes un archivo que se llama

descargar.php

Código PHP:

## Imaginando que el archivo no cambia.
$archivo "prueba.txt";
if ((isset(
$_GET['file'])) && (!empty($_GET['file'])) && ($archivo==$_GET['file'])){

##Generamos el archivo
$contenido "Hola Mundo.";
$f=fopen($archivo,"w");
fwrite($f,$contenido);
fclose($f);



$enlace $archivo
header ("Content-Disposition: attachment; filename=".$enlace); 
header ("Content-Type: application/octet-stream"); 
header ("Content-Length: ".filesize($enlace)); 
readfile($enlace); 


Y finalmente tengo mi archivo html con este link
<a href="descargar.php?file=prueba.txt">Archivo</a>