Php force download xml

I am creating an xml file on the fly. When the user creates this file, I want him to open the download file dialog with the created content. There is no actual file, because it is generated only through php. Any ideas on how to do this?

+3
source share
3 answers
+5
source

This is what worked for me. In readfile('newfile.xml');make sure the path to the file is correct. This php page is called from an html page with an anchor tag that says - download:

<?php 
header('Content-disposition: attachment; filename="newfile.xml"');
header('Content-type: "text/xml"; charset="utf8"');
readfile('newfile.xml');
?>

source: ?

+13
header('Content-disposition: attachment; filename=advertise.xml');
header ("Content-Type:text/xml"); 
//output the XML data
echo  $xml;
 // if you want to directly download then set expires time
header("Expires: 0");
+1

Source: https://habr.com/ru/post/1742404/


All Articles