开发者

php force download xml

I am creating an xml file on the fly. When a user generates this file I want it to open up a download file dialog with the content t开发者_StackOverflow社区hat was generated. There is no actual file because it is just generated through php. Any ideas on how to do this?


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

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

source: How do I force the browser to download a file to disk instead of playing or displaying it?


Send a content-disposition attachment header.


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜