Cep Posted December 12, 2006 Share Posted December 12, 2006 Hello,I have been getting my PHP code to output an xml file and now I have a button which allows the user to download that file.The button points to this code,[code=php:0]//**************************** DOWNLOAD XML ******************************************//if ($action=="xml") { if (isset($_POST['xml'])) { $xml = $_POST['xml']; } else { $xml = ""; } $xmlname = explode("/", $xml); header('Content-type: text/xml'); // It will be called downloaded.xml header('Content-Disposition: attachment; filename="'.$xmlname[1].'"'); // The XML source is in original.xml readfile($xml);}[/code]The post is a hidden input on the form which contains the filename and location of the xml file created, like this, "xml/myxml.xml"The button simply forces a download option box to appear so the user can save it to their system. This works beautifully however the problem is that part of the template code for the form is then being appended to the end of the xml files data. So I am getting something like this,[code]<?xml version='1.0' encoding='ISO-8859-1'?><report><row><orderid>4303</orderid><clientno>TT1010</clientno><clientname>YG</clientname><status>Order completed</status><product>Booklet</product></row><row><orderid>4304</orderid><clientno>MT1365</clientno><clientname>RD</clientname><status>Order completed</status><product>Booklet</product></row><row><orderid>4305</orderid><clientno>ME4460</clientno><clientname>HW</clientname><status>Order completed</status><product>Booklet</product></row></report><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>Budget System</title><link rel="stylesheet" type="text/css" href="css/main.css" />< script type="text/javascript" src="lib/script.js" ></ script ></head><body> <!-- header.tpl start --><table> <tr> <td width="20%"> Welcome User </td> <td width="20%"> Tue 12 Dec 2006 </td> <td width="60%"> <a href='index.php?sid=a381427e7ad36f19e98eef6f2e1784fe'>Back to Main</a> <a href='login.php?sid=a381427e7ad36f19e98eef6f2e1784fe&action=cp'>change password</a> <a href='login.php?sid=a381427e7ad36f19e98eef6f2e1784fe&action=lo'>[logout]</a> </td> </tr></table><!-- header.tpl end --></body></html>[/code]Any idea whats going on? Link to comment https://forums.phpfreaks.com/topic/30338-download-button-for-php-generated-xml-file/ Share on other sites More sharing options...
Cep Posted December 12, 2006 Author Share Posted December 12, 2006 Its ok, I just realised I am not using an EXIT; after my XML section and its running into the next part of my code :D Link to comment https://forums.phpfreaks.com/topic/30338-download-button-for-php-generated-xml-file/#findComment-139585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.