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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

SS_HTTPRequest::send_file puts spaces in front of text


Go to End


1145 Views

Avatar
Chris Dangerfield

Community Member, 8 Posts

19 November 2012 at 4:56pm

Hi There,

I am trying to create a dynamically generated downloadable calendar. Users click a link on the page and all the dates that are associated with that page get rendered by a template in ical format and then pushed back to the user as an ".ics" file. There are six spaces inserted before the rendered text which prevent Google calendar recognizing it. Does anyone have any idea why the SS_HTTPRequest::send_file() function would put six spaces at the beginning of a file. Here is the code:

// Function to generate a calendar to display the key dates
public function calendar() {

// Get the future key dates
$keyDates = DataObject::get("KeyDate", "`KeyDate` > CURDATE() AND `GrantPageID` = " . $this->ID, "", "", '');

// Make the data available to the template
$info = array(
'KeyDates' => $keyDates
);

// Code for passing a file rendered with the ss template "Calendar"
// and passed back to the browser
$filename = $this->Title . "_" . date('Y') . ".ics";
$calendar = ltrim($this->customise($info)->renderWith(array('Calendar')));

return SS_HTTPRequest::send_file($calendar, $filename, "text/calendar");

}