Jump to:

23461 Posts in 18908 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SS_HTTPRequest::send_file puts spaces in front of text

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

Page: 1
Go to End
Author Topic: 364 Views
  • Chris Dangerfield
    Avatar
    Community Member
    8 Posts

    SS_HTTPRequest::send_file puts spaces in front of text Link to this post

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

    364 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.