download txt file

1

I am currently using this method to download a query made.

mostrar_flush(1,"Espere un momento por favor mientras se termina  la consulta 90%......");

$retorno[] = $ArrayPlanoCGUNO;
    $retorno[] = "06";
    $codigo_serialize= base64_encode(serialize($retorno));
/*  
    echo '<form  id="frm1" name="frm1" action="http://evoluciondigital.com.co/websaas/interfase/historico-publicaciones/" method="post"  target="_blank"> 
          <input type="hidden" value="' . $codigo_serialize . '" name="datos">                     
          </form>';*/
      $urlServer='http://'.$_SERVER['SERVER_NAME'];

     echo '<form  id="frm1" name="frm1" action="'.$urlServer.'/interfase/index.php/historico-publicaciones/" method="post"  target="_blank"> 
             <input type="hidden" value="' . $codigo_serialize . '" name="datos">                     
             </form>'; 
    //Función que sirver para llamar el submit de el formulario y cargarse sin necesidad del boton enviar
    echo "<script>
          function formSubmit(){
            document.getElementById('frm1').submit();
          }
            formSubmit();
         </script>";

    terminar_flush(1);
    return true;

But it does not allow me to download the file to txt and it loads the server.

Is there any way to make it more optimal and not cause me so much inconvenience?

    
asked by Norbey Martinez 08.11.2016 в 21:07
source

1 answer

1

Print the text and put a header:

header("Content-Type: text/plain");
header('Content-Disposition: attachment; filename="default-filename.txt"')
echo $variable;

This will create a pop-up in the browser to download the variable $ content in a txt format, as in the example.

    
answered by 08.11.2016 в 22:44