I am trying to create xmlfile and download it from my program but it isnt working very well.
This is my code:
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><mydoc></mydoc>');
$xml->addAttribute('version', '1.0');
$xml->addChild('datetime', date('Y-m-d H:i:s'));
$person = $xml->addChild('person');
$person->addChild('firstname', 'Someone');
$person->addChild('secondname', 'Something');
$person->addChild('telephone', '123456789');
$person->addChild('email', '[email protected]');
$address = $person->addchild('address');
$address->addchild('homeaddress', 'Andersgatan 2, 432 10 Göteborg');
$address->addChild('workaddress', 'Andersgatan 3, 432 10 Göteborg');
$xml->saveXML('test.xml');
$response = Response::make($xml->asXML(), 200);
$response->header('Content-Type', 'text/xml');
return $response;
This is showing the xmlfile in my browser, but i want a popup to appear, asking me to download the file i just created. I tried it with Response::download() to but that isnt working neither because the first parameter should be the path to the file then.
Any help would be appreciated.
I think you might need to add some more headers:
$response->header('Cache-Control', 'public');
$response->header('Content-Description', 'File Transfer');
$response->header('Content-Disposition', 'attachment; filename=test.xml');
$response->header('Content-Transfer-Encoding', 'binary');
$response->header('Content-Type', 'text/xml');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With