D
D
denism3002020-04-27 16:41:42
PHP
denism300, 2020-04-27 16:41:42

How to give a file on the fly?

The function generates an xml file for subsequent return to the user.
It looks like this:

<?php
header("Content-Type: text/xml");
header("Content-disposition: attachment; filename=myFile.xml");

echo get_xml();
exit;

function get_xml()
{
    $xml = '';
    $xml .= 'bla-bla-bla';

    return $xml;
}

I get an error in the browser
Unable to connect to site.
The page may be temporarily unavailable or moved to a new address.
ERR_INVALID_RESPONSE

There are no errors in the XML content generation function, if you display it on the screen, then everything works.
How to fix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question