php force download xml

前端 未结 3 2013
星月不相逢
星月不相逢 2021-01-03 07:42

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 that was generated. There is no actual fil

相关标签:
3条回答
  • 2021-01-03 08:11

    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?

    0 讨论(0)
  • 2021-01-03 08:24

    Send a content-disposition attachment header.

    0 讨论(0)
  • 2021-01-03 08:24
    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 讨论(0)
提交回复
热议问题