Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php force download xml

Tags:

php

xml

download

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 file because it is just generated through php. Any ideas on how to do this?

like image 230
ngreenwood6 Avatar asked Nov 29 '22 05:11

ngreenwood6


1 Answers

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?

like image 58
Hari Gudigundla Avatar answered Dec 18 '22 11:12

Hari Gudigundla