Dead6re Posted January 23, 2008 Share Posted January 23, 2008 During runtime of a script, I have a XML file that is generated as a feed (export). Now the XML formatting is in Excel XML and I need a way to get the client to download the file instead of showing the file. How do I force a download of the file? Thanks, Dead6re Link to comment https://forums.phpfreaks.com/topic/87425-solved-force-download-excel-xml/ Share on other sites More sharing options...
The Little Guy Posted January 23, 2008 Share Posted January 23, 2008 I think something like this might work: <?php // We'll be outputting a XML header('Content-type: text/xml'); // It will be called downloaded.xml header('Content-Disposition: attachment; filename="downloaded.xml"'); // The XML source is in original.xml readfile('original.xml'); ?> Source: http://us.php.net/header Example#1 Download dialog Link to comment https://forums.phpfreaks.com/topic/87425-solved-force-download-excel-xml/#findComment-447187 Share on other sites More sharing options...
Dead6re Posted January 24, 2008 Author Share Posted January 24, 2008 Okay, that works for making the file downloadable but when I press open, it doesn't work. URL to test: http://nofear.getenjoyment.net/txml.php Link to comment https://forums.phpfreaks.com/topic/87425-solved-force-download-excel-xml/#findComment-447659 Share on other sites More sharing options...
mesje Posted January 24, 2008 Share Posted January 24, 2008 Okay, that works for making the file downloadable but when I press open, it doesn't work. URL to test: http://nofear.getenjoyment.net/txml.php works for me Link to comment https://forums.phpfreaks.com/topic/87425-solved-force-download-excel-xml/#findComment-447660 Share on other sites More sharing options...
lovesmith Posted January 24, 2008 Share Posted January 24, 2008 use the functions below function force_download ($data, $name, $mimetype='', $filesize=false) { // File size not set? if ($filesize == false OR !is_numeric($filesize)) { $filesize = strlen($data); } // Mimetype not set? if (empty($mimetype)) { $mimetype = 'application/octet-stream'; } // Make sure there's not anything else left ob_clean_all(); // Start sending headers header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Transfer-Encoding: binary"); header("Content-Type: " . $mimetype); header("Content-Length: " . $filesize); header("Content-Disposition: attachment; filename=\"" . $name . "\";" ); // Send data echo $data; die(); } force_download($strdata,"orders.txt",'',''); //$strdata is the data that holds the output contents. HOpe this helps Link to comment https://forums.phpfreaks.com/topic/87425-solved-force-download-excel-xml/#findComment-447662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.