Hey guys I was wondering how I could download a file that is generated on the fly by PHP. The file I want to download would be an XML file. At the moment all my code does is create a long string with all of the data that is to put in the file, it then simply writes the string to a file and saves it with a .XML extension. This is currently working in my local machine using a copy of the website, it won’t work on the web server though due to read/write permissions.
So is there a way to generate a file in the fly to be immediately downloaded without storing it on the web server?
If the same script is generating the file, you could
echoorprintthe contents on to the page and useheaderto force download.And if you have a different file for downloading the file, just use
file_get_contentsand output the file data!That should do you 🙂