Working with php string

Asked

Viewed 62 times

4

I have a project to issue the file of remittance slips to banks and credit unions. In the file mount I define a variable and mount the lines as in the example below:

$conteudo .= '085';                                                        
$conteudo .= '0000';                                                       
$conteudo .= '0';

I wonder if it is possible, in the end, to generate this information in file format and force the download without creating the file physically on the server.

  • 2

    Yes it is possible! would be more or less like in this reply

  • To supplement the question it is better that you click edit instead of creating an answer. Regarding the problem of the two line breaks. Make sure there are no line breaks before opening the php <?php tag. Or if you are included other files. Check that in these files there is no line break also after closing the tag ? >. Also, it is not recommended to use the closing tag if you are not going to include static (HTML) content afterwards.

1 answer

4

Yeah, that should do it:

$fileName = "remessa.txt"; //colocar aqui o nome do arquivo



header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream;");
header("Content-Length:".strlen($conteudo));
header("Content-disposition: attachment; filename=".$fileName);
die($conteudo);
  • 1

    True. I’d forgotten that detail.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.