Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Problem with creating export facility

Go to End

4 Posts   980 Views


Community Member, 9 Posts

7 January 2012 at 4:25am

I am trying to add an "export as RTF" facility to my website. The code which handles the /export url call basically creates the appropriate export content and then sends the Content-type header as text/rtf and echo's the export content.

All is well in most browsers, but in Internet Explorer 8 (i'm not sure about other IE versions) I get "Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found"

The same thing happens if I use SS_HTTPRequest::send_file.

I've been searching around for ages for a solution but can't find anything. This code works perfectly well from a test php file outside SilverStripe. Has any-one seen this before? Does any-one know how to get round the problem?



Forum Moderator, 5523 Posts

7 January 2012 at 8:57pm

Could you post the code you're trying to use in SS.

SS will possibly override your header and include it in the template so after you echo the result (you should just use a template) perhaps include a die().

Echoing anything kinda goes against SilverStripe, you should instead use renderWidth() and put your RTF text in a template (template files can be anything, not just html);

function export() {
return $this->customize(new ArrayData(
array('Foo' => 'bar')

Then in themes/yourtheme/templates/ include your data, that array I passed into customize will provide $Foo to the template and you can add whatever you need.


Community Member, 9 Posts

9 January 2012 at 11:25pm


Thanks for your help. I have incorporated your feedback so my code now looks like this

header("Content-type: text/rtf");
header("Content-Disposition: attachment; filename=".$this->exportFileName().".rtf");
$rtf = convert2rtf::convert($content);
return $this->renderWith(

As you can see, I'm using a library to convert to RTF so I pass the converted content to my template which contains only $RTF.

This has fixed my original bug - now content is sent to a file download dialog in all browsers. But, browsers seem to be ignoring my content-type and filename headers.

I can't find anywhere in the SilverStripe code where I can control those - have I overlooked it, or is this not supported?


Forum Moderator, 5523 Posts

9 January 2012 at 11:43pm

SS is likely overridding your header() calls with it's own. Try setting $this->response->addHeader();