Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Let user download a XML file

Tags:

php

header

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?

like image 248
PeeHaa Avatar asked Dec 03 '10 19:12

PeeHaa


People also ask

How do I download an XML file in Chrome?

Simply click the File button (the 3 lines), and click Save Page As. For example, I went to xml-sitemaps.com/sitemap.xml and clicked Save Page As. It saved as XML to my local machine and loaded as such. Without any HTML.

How do I download an XML file from GitHub?

If you're trying to download a file from the GitHub Web App, just right-click on the Raw button and select “Save Link As”. That should download the file as an XML to your machine.


1 Answers

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

echo $xml_contents;
like image 140
Ish Avatar answered Nov 05 '22 16:11

Ish