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.

General Questions /

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

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

SS_HTTPRequest::send_file puts spaces in front of text


Reply


420 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");
      
}