Search code examples
phpheader

Let user download a XML file


I have prepared an XML string in PHP and I would like to let the user download the string in an XML file.

Is it possible to offer the user the download (e.g. text.xml) without physically saving the xml file to the server?


Solution

  • <?php
    header('Content-type: text/xml');
    header('Content-Disposition: attachment; filename="text.xml"');
    
    echo $xml_contents;