Download XML by browser, without opening the file

Asked

Viewed 871 times

1

I need the system to download an XML file, release the file itself, without opening it in the browser, has as?

  • I believe so.

  • Yes you have how to use readfile (php), XMLHttpRequest (javascript) and ajax (jquery)

1 answer

2

There is. Do it like this

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

or

<?php 
header('Content-disposition: attachment; filename="file.xml"');
header('Content-type: "text/xml"; charset="utf8"');
echo "<?xml version="1.0" encoding="UTF-8"?>
<root>
<tag>Oi</tag>
</root>
";
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.