SSbits - Home page
Site by Carbon Crayon
Submit a Post >

Snippets - Little bits of code to make you happy

Creating a Page Export Function

Need to create an 'export' function for a page? Do it quickly and cleanly with HTTP::sendFileToBrowser. In your page controller, add a new action 'export':


class Page_Controller extends ContentController
	static $allowed_actions = array(

	function export() 
		$filename = "PageExport.html";
		$data = $this->renderWith(array('Page_Export'));
		HTTP::sendFileToBrowser($data, $filename);

Now you just need to create, and direct the user to the URL "/export/". Your page will be returned to the browser as an attachment to download.

Hamish Campbell avatar

Hamish Campbell

Hamish is a web developer for Opus International Consultants in New Zealand. He creates tools for managing data online, with a particular interest in geographical information systems. He is also an active contributor to the SilverStripe open source project.

  • Darren-Lee
    09/04/2011 11:54am (6 years ago)

    Nice and simple! I am using this for an Estate Agency website that needs to export it's data to in order to import into RightMove.

  • Hibari
    23/06/2011 9:48pm (6 years ago)

    Hey Hamish, I really like the way that this function is supposed to work. I've been trying to use it in Silverstripe 2.4.5, and so far I'm not having any luck, every time it's pushing the error in php saying "undefined method HTTP::sendFileToBrowser() any idea on how to fix that?

  • OPen
    18/10/2012 10:19am (5 years ago)

    This api is deprecated since 2.3 as mentioned here :

Post a comment ...

You cannot post comments until you have logged in. Login Here.


Site of the Month

Find SSbits on

Top Contributers

Rank Avatar Name
1 article image Aram Balakjian
2 article image wfacewomens
3 article image Daniel Hensby
4 article image Marcus Dalgren
5 article image ryduhartchas
6 article image Hamish Campbell
7 article image Ty Barho
8 article image Martijn van Nieuwenhoven
9 article image Darren-Lee
10 article image Roman Schmid

View full leaderboard